Migrate from com.jcraft:jsch 0.1.55 to com.github.mwiede:jsch 0.2.5

com.jcraft:jsch is not actively maintained anymore and lacks support
for modern public key algorithms such as rsa-sha2-256. It only
supports ssh-rsa which is disabled in up-to-date environments.

com.github.mwiede:jsch was created as a drop-in replacement which
works in modern environments [1].

Sources are taken from maven central [2]. The following files were
omitted, because they depend on additional 3rd-party libraries which
we do not have / do not need:

    com/jcraft/jsch/JUnixSocketFactory.java
    com/jcraft/jsch/Log4j2Logger.java
    com/jcraft/jsch/PageantConnector.java
    com/jcraft/jsch/Slf4jLogger.java
    com/jcraft/jsch/SSHAgentConnector.java
    com/jcraft/jsch/bc/*
    com/jcraft/jsch/jgss/GSSContextKrb5.java

Fixes #1812.

[1] https://github.com/mwiede/jsch
[2] https://repo1.maven.org/maven2/com/github/mwiede/jsch/0.2.5/jsch-0.2.5-sources.jar
This commit is contained in:
Sebastian Ratz
2023-01-03 14:58:23 +01:00
parent ce6556496e
commit e3ce7fe95a
193 changed files with 15652 additions and 3200 deletions

View File

@@ -0,0 +1,36 @@
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
/*
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;
}

View File

@@ -0,0 +1,80 @@
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
/*
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
@Deprecated
public boolean decrypt() {
throw new RuntimeException("not implemented");
}
@Override
public String getAlgName() { return algname; }
@Override
public String getName() { return comment; }
@Override
public boolean isEncrypted() { return false; }
@Override
public void clear() { }
}

View File

@@ -0,0 +1,75 @@
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
/*
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;
}
}
}

View File

@@ -0,0 +1,256 @@
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
/*
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;
}
}

View File

@@ -1,6 +1,6 @@
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
/*
Copyright (c) 2006-2018 ymnk, JCraft,Inc. All rights reserved.
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:
@@ -27,25 +27,14 @@ 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.jcraft;
package com.jcraft.jsch;
import com.jcraft.jsch.MAC;
import java.security.*;
public class HMACSHA1 extends HMAC implements MAC{
private static final String name="hmac-sha1";
public HMACSHA1(){
super();
MessageDigest md=null;
try{ md=MessageDigest.getInstance("SHA-1"); }
catch(Exception e){
System.err.println(e);
public class AgentProxyException extends Exception {
private static final long serialVersionUID=-1L;
public AgentProxyException(String message){
super(message);
}
setH(md);
}
public String getName(){
return name;
public AgentProxyException(String message, Throwable e){
super(message, e);
}
}

View File

@@ -29,14 +29,10 @@ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package com.jcraft.jsch;
import java.io.PipedInputStream;
import java.io.PipedOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.IOException;
import java.io.*;
import java.util.Vector;
public abstract class Channel implements Runnable{
public abstract class Channel{
static final int SSH_MSG_CHANNEL_OPEN_CONFIRMATION= 91;
static final int SSH_MSG_CHANNEL_OPEN_FAILURE= 92;
@@ -48,41 +44,49 @@ public abstract class Channel implements Runnable{
static final int SSH_OPEN_RESOURCE_SHORTAGE= 4;
static int index=0;
private static java.util.Vector pool=new java.util.Vector();
static Channel getChannel(String type){
private static Vector<Channel> pool=new Vector<>();
static Channel getChannel(String type, Session session){
Channel ret = null;
if(type.equals("session")){
return new ChannelSession();
ret = new ChannelSession();
}
if(type.equals("shell")){
return new ChannelShell();
ret = new ChannelShell();
}
if(type.equals("exec")){
return new ChannelExec();
ret = new ChannelExec();
}
if(type.equals("x11")){
return new ChannelX11();
ret = new ChannelX11();
}
if(type.equals("auth-agent@openssh.com")){
return new ChannelAgentForwarding();
ret = new ChannelAgentForwarding();
}
if(type.equals("direct-tcpip")){
return new ChannelDirectTCPIP();
ret = new ChannelDirectTCPIP();
}
if(type.equals("forwarded-tcpip")){
return new ChannelForwardedTCPIP();
ret = new ChannelForwardedTCPIP();
}
if(type.equals("sftp")){
return new ChannelSftp();
ret = new ChannelSftp();
}
if(type.equals("subsystem")){
return new ChannelSubsystem();
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=(Channel)(pool.elementAt(i));
Channel c=pool.elementAt(i);
if(c.id==id && c.session==session) return c;
}
}
@@ -119,7 +123,7 @@ public abstract class Channel implements Runnable{
volatile int reply=0;
volatile int connectTimeout=0;
private Session session;
protected Session session;
int notifyme=0;
@@ -231,7 +235,7 @@ public abstract class Channel implements Runnable{
private Buffer buffer=null;
private Packet packet=null;
private boolean closed=false;
private synchronized void init() throws java.io.IOException{
private synchronized void init() throws IOException{
buffer=new Buffer(rmpsize);
packet=new Packet(buffer);
@@ -244,17 +248,19 @@ public abstract class Channel implements Runnable{
}
byte[] b=new byte[1];
public void write(int w) throws java.io.IOException{
@Override
public void write(int w) throws IOException{
b[0]=(byte)w;
write(b, 0, 1);
}
public void write(byte[] buf, int s, int l) throws java.io.IOException{
@Override
public void write(byte[] buf, int s, int l) throws IOException{
if(packet==null){
init();
}
if(closed){
throw new java.io.IOException("Already closed");
throw new IOException("Already closed");
}
byte[] _buf=buffer.buffer;
@@ -277,9 +283,10 @@ public abstract class Channel implements Runnable{
}
}
public void flush() throws java.io.IOException{
@Override
public void flush() throws IOException{
if(closed){
throw new java.io.IOException("Already closed");
throw new IOException("Already closed");
}
if(dataLen==0)
return;
@@ -298,16 +305,17 @@ public abstract class Channel implements Runnable{
}
catch(Exception e){
close();
throw new java.io.IOException(e.toString());
throw new IOException(e.toString(), e);
}
}
public void close() throws java.io.IOException{
@Override
public void close() throws IOException{
if(packet==null){
try{
init();
}
catch(java.io.IOException e){
catch(IOException e){
// close should be finished silently.
return;
}
@@ -325,7 +333,7 @@ public abstract class Channel implements Runnable{
return out;
}
class MyPipedInputStream extends PipedInputStream{
static class MyPipedInputStream extends PipedInputStream{
private int BUFFER_SIZE = 1024;
private int max_buffer_size = BUFFER_SIZE;
MyPipedInputStream() throws IOException{ super(); }
@@ -427,8 +435,7 @@ public abstract class Channel implements Runnable{
}
void setRemotePacketSize(int foo){ this.rmpsize=foo; }
public void run(){
}
abstract void run();
void write(byte[] foo) throws IOException {
write(foo, 0, foo.length);
@@ -547,7 +554,7 @@ public abstract class Channel implements Runnable{
channels=new Channel[pool.size()];
for(int i=0; i<pool.size(); i++){
try{
Channel c=((Channel)(pool.elementAt(i)));
Channel c=pool.elementAt(i);
if(c.session==session){
channels[count++]=c;
}
@@ -621,24 +628,25 @@ public abstract class Channel implements Runnable{
}
*/
class PassiveInputStream extends MyPipedInputStream{
PipedOutputStream out;
static class PassiveInputStream extends MyPipedInputStream{
PipedOutputStream os;
PassiveInputStream(PipedOutputStream out, int size) throws IOException{
super(out, size);
this.out=out;
this.os=out;
}
PassiveInputStream(PipedOutputStream out) throws IOException{
super(out);
this.out=out;
this.os=out;
}
@Override
public void close() throws IOException{
if(out!=null){
this.out.close();
if(this.os!=null){
this.os.close();
}
out=null;
this.os=null;
}
}
class PassiveOutputStream extends PipedOutputStream{
static class PassiveOutputStream extends PipedOutputStream{
private MyPipedInputStream _sink=null;
PassiveOutputStream(PipedInputStream in,
boolean resizable_buffer) throws IOException{
@@ -647,12 +655,14 @@ public abstract class Channel implements Runnable{
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);
@@ -678,7 +688,7 @@ public abstract class Channel implements Runnable{
public int getId(){ return id; }
protected void sendOpenConfirmation() throws Exception{
Buffer buf=new Buffer(100);
Buffer buf=new Buffer(200);
Packet packet=new Packet(buf);
packet.reset();
buf.putByte((byte)SSH_MSG_CHANNEL_OPEN_CONFIRMATION);
@@ -691,7 +701,7 @@ public abstract class Channel implements Runnable{
protected void sendOpenFailure(int reasoncode){
try{
Buffer buf=new Buffer(100);
Buffer buf=new Buffer(200);
Packet packet=new Packet(buf);
packet.reset();
buf.putByte((byte)SSH_MSG_CHANNEL_OPEN_FAILURE);
@@ -706,7 +716,7 @@ public abstract class Channel implements Runnable{
}
protected Packet genChannelOpenPacket(){
Buffer buf=new Buffer(100);
Buffer buf=new Buffer(200);
Packet packet=new Packet(buf);
// byte SSH_MSG_CHANNEL_OPEN(90)
// string channel type //
@@ -750,7 +760,7 @@ public abstract class Channel implements Runnable{
this.notifyme=1;
wait(t);
}
catch(java.lang.InterruptedException e){
catch(InterruptedException e){
}
finally{
this.notifyme=0;

View File

@@ -29,6 +29,7 @@ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package com.jcraft.jsch;
import java.io.IOException;
import java.net.*;
import java.util.Vector;
@@ -37,26 +38,28 @@ class ChannelAgentForwarding extends Channel{
static private final int LOCAL_WINDOW_SIZE_MAX=0x20000;
static private final int LOCAL_MAXIMUM_PACKET_SIZE=0x4000;
private final byte SSH_AGENTC_REQUEST_RSA_IDENTITIES = 1;
private final byte SSH_AGENT_RSA_IDENTITIES_ANSWER = 2;
private final byte SSH_AGENTC_RSA_CHALLENGE = 3;
private final byte SSH_AGENT_RSA_RESPONSE = 4;
private final byte SSH_AGENT_FAILURE = 5;
private final byte SSH_AGENT_SUCCESS = 6;
private final byte SSH_AGENTC_ADD_RSA_IDENTITY = 7;
private final byte SSH_AGENTC_REMOVE_RSA_IDENTITY = 8;
private final byte SSH_AGENTC_REMOVE_ALL_RSA_IDENTITIES = 9;
static private final byte SSH_AGENTC_REQUEST_RSA_IDENTITIES = 1;
static private final byte SSH_AGENT_RSA_IDENTITIES_ANSWER = 2;
static private final byte SSH_AGENTC_RSA_CHALLENGE = 3;
static private final byte SSH_AGENT_RSA_RESPONSE = 4;
static private final byte SSH_AGENT_FAILURE = 5;
static private final byte SSH_AGENT_SUCCESS = 6;
static private final byte SSH_AGENTC_ADD_RSA_IDENTITY = 7;
static private final byte SSH_AGENTC_REMOVE_RSA_IDENTITY = 8;
static private final byte SSH_AGENTC_REMOVE_ALL_RSA_IDENTITIES = 9;
private final byte SSH2_AGENTC_REQUEST_IDENTITIES=11;
private final byte SSH2_AGENT_IDENTITIES_ANSWER=12;
private final byte SSH2_AGENTC_SIGN_REQUEST=13;
private final byte SSH2_AGENT_SIGN_RESPONSE=14;
private final byte SSH2_AGENTC_ADD_IDENTITY=17;
private final byte SSH2_AGENTC_REMOVE_IDENTITY=18;
private final byte SSH2_AGENTC_REMOVE_ALL_IDENTITIES=19;
private final byte SSH2_AGENT_FAILURE=30;
static private final byte SSH2_AGENTC_REQUEST_IDENTITIES=11;
static private final byte SSH2_AGENT_IDENTITIES_ANSWER=12;
static private final byte SSH2_AGENTC_SIGN_REQUEST=13;
static private final byte SSH2_AGENT_SIGN_RESPONSE=14;
static private final byte SSH2_AGENTC_ADD_IDENTITY=17;
static private final byte SSH2_AGENTC_REMOVE_IDENTITY=18;
static private final byte SSH2_AGENTC_REMOVE_ALL_IDENTITIES=19;
static private final byte SSH2_AGENT_FAILURE=30;
boolean init=true;
//static private final int SSH_AGENT_OLD_SIGNATURE=0x1;
static private final int SSH_AGENT_RSA_SHA2_256=0x2;
static private final int SSH_AGENT_RSA_SHA2_512=0x4;
private Buffer rbuf=null;
private Buffer wbuf=null;
@@ -79,7 +82,8 @@ class ChannelAgentForwarding extends Channel{
connected=true;
}
public void run(){
@Override
void run(){
try{
sendOpenConfirmation();
}
@@ -89,7 +93,8 @@ class ChannelAgentForwarding extends Channel{
}
}
void write(byte[] foo, int s, int l) throws java.io.IOException {
@Override
void write(byte[] foo, int s, int l) throws IOException {
if(packet==null){
wbuf=new Buffer(rmpsize);
@@ -118,7 +123,7 @@ class ChannelAgentForwarding extends Channel{
_session=getSession();
}
catch(JSchException e){
throw new java.io.IOException(e.toString());
throw new IOException(e.toString(), e);
}
IdentityRepository irepo = _session.getIdentityRepository();
@@ -128,17 +133,17 @@ class ChannelAgentForwarding extends Channel{
if(typ==SSH2_AGENTC_REQUEST_IDENTITIES){
mbuf.putByte(SSH2_AGENT_IDENTITIES_ANSWER);
Vector identities = irepo.getIdentities();
Vector<Identity> identities = irepo.getIdentities();
synchronized(identities){
int count=0;
for(int i=0; i<identities.size(); i++){
Identity identity=(Identity)(identities.elementAt(i));
Identity identity=identities.elementAt(i);
if(identity.getPublicKeyBlob()!=null)
count++;
}
mbuf.putInt(count);
for(int i=0; i<identities.size(); i++){
Identity identity=(Identity)(identities.elementAt(i));
Identity identity=identities.elementAt(i);
byte[] pubkeyblob=identity.getPublicKeyBlob();
if(pubkeyblob==null)
continue;
@@ -156,15 +161,15 @@ class ChannelAgentForwarding extends Channel{
byte[] data=rbuf.getString();
int flags=rbuf.getInt();
// if((flags & 1)!=0){ //SSH_AGENT_OLD_SIGNATURE // old OpenSSH 2.0, 2.1
// if((flags & SSH_AGENT_OLD_SIGNATURE)!=0){ // old OpenSSH 2.0, 2.1
// datafellows = SSH_BUG_SIGBLOB;
// }
Vector identities = irepo.getIdentities();
Vector<Identity> identities = irepo.getIdentities();
Identity identity = null;
synchronized(identities){
for(int i=0; i<identities.size(); i++){
Identity _identity=(Identity)(identities.elementAt(i));
Identity _identity=identities.elementAt(i);
if(_identity.getPublicKeyBlob()==null)
continue;
if(!Util.array_equals(blob, _identity.getPublicKeyBlob())){
@@ -205,8 +210,23 @@ class ChannelAgentForwarding extends Channel{
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);
@@ -259,6 +279,7 @@ class ChannelAgentForwarding extends Channel{
}
}
@Override
void eof_remote(){
super.eof_remote();
eof();

View File

@@ -0,0 +1,71 @@
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 {
static private final int LOCAL_WINDOW_SIZE_MAX = 0x20000;
static private final int LOCAL_MAXIMUM_PACKET_SIZE = 0x4000;
static private final byte[] _type = Util.str2byte("direct-streamlocal@openssh.com");
private String socketPath;
ChannelDirectStreamLocal() {
super();
type = _type;
setLocalWindowSizeMax(LOCAL_WINDOW_SIZE_MAX);
setLocalWindowSize(LOCAL_WINDOW_SIZE_MAX);
setLocalPacketSize(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.buffer_margin);
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;
}
}

View File

@@ -50,10 +50,12 @@ public class ChannelDirectTCPIP extends Channel{
setLocalPacketSize(LOCAL_MAXIMUM_PACKET_SIZE);
}
@Override
void init (){
io=new IO();
}
@Override
public void connect(int connectTimeout) throws JSchException{
this.connectTimeout=connectTimeout;
try{
@@ -63,7 +65,7 @@ public class ChannelDirectTCPIP extends Channel{
}
if(io.in!=null){
thread=new Thread(this);
thread=new Thread(this::run);
thread.setName("DirectTCPIP thread "+_session.getHost());
if(_session.daemon_thread){
thread.setDaemon(_session.daemon_thread);
@@ -84,7 +86,8 @@ public class ChannelDirectTCPIP extends Channel{
}
}
public void run(){
@Override
void run(){
try{
sendChannelOpen();
@@ -133,9 +136,11 @@ public class ChannelDirectTCPIP extends Channel{
disconnect();
}
@Override
public void setInputStream(InputStream in){
io.setInputStream(in);
}
@Override
public void setOutputStream(OutputStream out){
io.setOutputStream(out);
}
@@ -145,6 +150,7 @@ public class ChannelDirectTCPIP extends Channel{
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() +

View File

@@ -29,12 +29,14 @@ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package com.jcraft.jsch;
import java.io.*;
import java.util.*;
public class ChannelExec extends ChannelSession{
byte[] command=new byte[0];
@Override
public void start() throws JSchException{
Session _session=getSession();
try{
@@ -44,13 +46,11 @@ public class ChannelExec extends ChannelSession{
}
catch(Exception e){
if(e instanceof JSchException) throw (JSchException)e;
if(e instanceof Throwable)
throw new JSchException("ChannelExec", (Throwable)e);
throw new JSchException("ChannelExec");
throw new JSchException("ChannelExec", e);
}
if(io.in!=null){
thread=new Thread(this);
thread=new Thread(this::run);
thread.setName("Exec thread "+_session.getHost());
if(_session.daemon_thread){
thread.setDaemon(_session.daemon_thread);
@@ -66,18 +66,19 @@ public class ChannelExec extends ChannelSession{
this.command=command;
}
@Override
void init() throws JSchException {
io.setInputStream(getSession().in);
io.setOutputStream(getSession().out);
}
public void setErrStream(java.io.OutputStream out){
public void setErrStream(OutputStream out){
setExtOutputStream(out);
}
public void setErrStream(java.io.OutputStream out, boolean dontclose){
public void setErrStream(OutputStream out, boolean dontclose){
setExtOutputStream(out, dontclose);
}
public java.io.InputStream getErrStream() throws java.io.IOException {
public InputStream getErrStream() throws IOException {
return getExtInputStream();
}
}

View File

@@ -35,7 +35,7 @@ import java.util.Vector;
public class ChannelForwardedTCPIP extends Channel{
private static Vector pool = new Vector();
private static Vector<Config> pool = new Vector<>();
static private final int LOCAL_WINDOW_SIZE_MAX=0x20000;
//static private final int LOCAL_WINDOW_SIZE_MAX=0x100000;
@@ -56,12 +56,13 @@ public class ChannelForwardedTCPIP extends Channel{
connected=true;
}
@Override
public void run(){
try{
if(config instanceof ConfigDaemon){
ConfigDaemon _config = (ConfigDaemon)config;
Class c=Class.forName(_config.target);
daemon=(ForwardedTCPIPDaemon)c.newInstance();
Class<? extends ForwardedTCPIPDaemon> c=Class.forName(_config.target).asSubclass(ForwardedTCPIPDaemon.class);
daemon=c.getDeclaredConstructor().newInstance();
PipedOutputStream out=new PipedOutputStream();
io.setInputStream(new PassiveInputStream(out
@@ -128,6 +129,7 @@ public class ChannelForwardedTCPIP extends Channel{
disconnect();
}
@Override
void getData(Buffer buf){
setRecipient(buf.getInt());
setRemoteWindowSize(buf.getUInt());
@@ -157,8 +159,8 @@ public class ChannelForwardedTCPIP extends Channel{
this.config = getPort(_session, null, port);
if(this.config == null){
if(JSch.getLogger().isEnabled(Logger.ERROR)){
JSch.getLogger().log(Logger.ERROR,
if(_session.getLogger().isEnabled(Logger.ERROR)){
_session.getLogger().log(Logger.ERROR,
"ChannelForwardedTCPIP: "+Util.byte2str(addr)+":"+port+" is not registered.");
}
}
@@ -167,7 +169,7 @@ public class ChannelForwardedTCPIP extends Channel{
private static Config getPort(Session session, String address_to_bind, int rport){
synchronized(pool){
for(int i=0; i<pool.size(); i++){
Config bar = (Config)(pool.elementAt(i));
Config bar = pool.elementAt(i);
if(bar.session != session) continue;
if(bar.rport != rport) {
if(bar.rport != 0 || bar.allocated_rport != rport)
@@ -182,19 +184,21 @@ public class ChannelForwardedTCPIP extends Channel{
}
static String[] getPortForwarding(Session session){
Vector foo = new Vector();
Vector<String> foo = new Vector<>();
synchronized(pool){
for(int i=0; i<pool.size(); i++){
Config config = (Config)(pool.elementAt(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]=(String)(foo.elementAt(i));
bar[i]=foo.elementAt(i);
}
return bar;
}
@@ -269,7 +273,7 @@ public class ChannelForwardedTCPIP extends Channel{
}
}
Buffer buf=new Buffer(100); // ??
Buffer buf=new Buffer(200); // ??
Packet packet=new Packet(buf);
try{
@@ -287,7 +291,7 @@ public class ChannelForwardedTCPIP extends Channel{
session.write(packet);
}
catch(Exception e){
// throw new JSchException(e.toString());
// throw new JSchException(e.toString(), e);
}
}
static void delPort(Session session){
@@ -296,7 +300,7 @@ public class ChannelForwardedTCPIP extends Channel{
synchronized(pool){
rport=new int[pool.size()];
for(int i=0; i<pool.size(); i++){
Config config = (Config)(pool.elementAt(i));
Config config = pool.elementAt(i);
if(config.session == session) {
rport[count++]=config.rport; // ((Integer)bar[1]).intValue();
}

View File

@@ -36,7 +36,7 @@ class ChannelSession extends Channel{
protected boolean agent_forwarding=false;
protected boolean xforwading=false;
protected Hashtable env=null;
protected Hashtable<byte[], byte[]> env=null;
protected boolean pty=false;
@@ -68,16 +68,18 @@ class ChannelSession extends Channel{
*
* @param enable
*/
@Override
public void setXForwarding(boolean enable){
xforwading=enable;
}
/**
* @deprecated Use {@link #setEnv(String, String)} or {@link #setEnv(byte[], byte[])} instead.
* @deprecated Use #setEnv(String, String) or #setEnv(byte[], byte[]) instead.
* @see #setEnv(String, String)
* @see #setEnv(byte[], byte[])
*/
public void setEnv(Hashtable env){
@Deprecated
public void setEnv(Hashtable<byte[], byte[]> env){
synchronized(this){
this.env=env;
}
@@ -111,9 +113,9 @@ class ChannelSession extends Channel{
}
}
private Hashtable getEnv(){
private Hashtable<byte[], byte[]> getEnv(){
if(env==null)
env=new Hashtable();
env=new Hashtable<>();
return env;
}
@@ -213,9 +215,9 @@ class ChannelSession extends Channel{
}
if(env!=null){
for(Enumeration _env=env.keys(); _env.hasMoreElements();){
Object name=_env.nextElement();
Object value=env.get(name);
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));
@@ -231,7 +233,8 @@ class ChannelSession extends Channel{
return (byte[])o;
}
public void run(){
@Override
void run(){
//System.err.println(this+":run >");
Buffer buf=new Buffer(rmpsize);

View File

@@ -30,7 +30,9 @@ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package com.jcraft.jsch;
import java.io.*;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.Hashtable;
import java.util.Vector;
public class ChannelSftp extends ChannelSession{
@@ -146,7 +148,7 @@ public class ChannelSftp extends ChannelSession{
private int server_version=3;
private String version=String.valueOf(client_version);
private java.util.Hashtable extensions=null;
private Hashtable<String, String> extensions=null;
private InputStream io_in=null;
private boolean extension_posix_rename = false;
@@ -170,16 +172,15 @@ public class ChannelSftp extends ChannelSession{
o Implementation changes, no actual protocol changes.
*/
private static final String file_separator=java.io.File.separator;
private static final char file_separatorc=java.io.File.separatorChar;
private static boolean fs_is_bs=(byte)java.io.File.separatorChar == '\\';
private static final String file_separator=File.separator;
private static final char file_separatorc=File.separatorChar;
private static boolean fs_is_bs=(byte)File.separatorChar == '\\';
private String cwd;
private String home;
private String lcwd;
private static final String UTF8="UTF-8";
private String fEncoding=UTF8;
private Charset fEncoding=StandardCharsets.UTF_8;
private boolean fEncoding_is_utf8=true;
private RequestQueue rq = new RequestQueue(16);
@@ -216,15 +217,17 @@ public class ChannelSftp extends ChannelSession{
setLocalPacketSize(LOCAL_MAXIMUM_PACKET_SIZE);
}
@Override
void init(){
}
@Override
public void start() throws JSchException{
try{
PipedOutputStream pos=new PipedOutputStream();
io.setOutputStream(pos);
PipedInputStream pis=new MyPipedInputStream(pos, rmpsize);
PipedInputStream pis=new MyPipedInputStream(pos, rq.size()*rmpsize);
io.setInputStream(pis);
io_in=io.in;
@@ -268,7 +271,7 @@ public class ChannelSftp extends ChannelSession{
type=header.type; // 2 -> SSH_FXP_VERSION
server_version=header.rid;
//System.err.println("SFTP protocol server-version="+server_version);
extensions=new java.util.Hashtable();
extensions=new Hashtable<>();
if(length>0){
// extension data
fill(buf, length);
@@ -311,9 +314,7 @@ public class ChannelSftp extends ChannelSession{
catch(Exception e){
//System.err.println(e);
if(e instanceof JSchException) throw (JSchException)e;
if(e instanceof Throwable)
throw new JSchException(e.toString(), (Throwable)e);
throw new JSchException(e.toString());
throw new JSchException(e.toString(), e);
}
}
@@ -355,9 +356,7 @@ public class ChannelSftp extends ChannelSession{
}
catch(Exception e){
if(e instanceof SftpException) throw (SftpException)e;
if(e instanceof Throwable)
throw new SftpException(SSH_FX_FAILURE, "", (Throwable)e);
throw new SftpException(SSH_FX_FAILURE, "");
throw new SftpException(SSH_FX_FAILURE, e.toString(), e);
}
}
@@ -391,7 +390,7 @@ public class ChannelSftp extends ChannelSession{
src=localAbsolutePath(src);
dst=remoteAbsolutePath(dst);
Vector v=glob_remote(dst);
Vector<String> v=glob_remote(dst);
int vsize=v.size();
if(vsize!=1){
if(vsize==0){
@@ -403,7 +402,7 @@ public class ChannelSftp extends ChannelSession{
throw new SftpException(SSH_FX_FAILURE, v.toString());
}
else{
dst=(String)(v.elementAt(0));
dst=v.elementAt(0);
}
boolean isRemoteDir=isRemoteDir(dst);
@@ -411,12 +410,12 @@ public class ChannelSftp extends ChannelSession{
v=glob_local(src);
vsize=v.size();
StringBuffer dstsb=null;
StringBuilder dstsb=null;
if(isRemoteDir){
if(!dst.endsWith("/")){
dst+="/";
}
dstsb=new StringBuffer(dst);
dstsb=new StringBuilder(dst);
}
else if(vsize>1){
throw new SftpException(SSH_FX_FAILURE,
@@ -424,7 +423,7 @@ public class ChannelSftp extends ChannelSession{
}
for(int j=0; j<vsize; j++){
String _src=(String)(v.elementAt(j));
String _src=v.elementAt(j);
String _dst=null;
if(isRemoteDir){
int i=_src.lastIndexOf(file_separatorc);
@@ -483,9 +482,7 @@ public class ChannelSftp extends ChannelSession{
}
catch(Exception e){
if(e instanceof SftpException) throw (SftpException)e;
if(e instanceof Throwable)
throw new SftpException(SSH_FX_FAILURE, e.toString(), (Throwable)e);
throw new SftpException(SSH_FX_FAILURE, e.toString());
throw new SftpException(SSH_FX_FAILURE, e.toString(), e);
}
}
public void put(InputStream src, String dst) throws SftpException{
@@ -516,7 +513,7 @@ public class ChannelSftp extends ChannelSession{
dst=remoteAbsolutePath(dst);
Vector v=glob_remote(dst);
Vector<String> v=glob_remote(dst);
int vsize=v.size();
if(vsize!=1){
if(vsize==0){
@@ -528,7 +525,7 @@ public class ChannelSftp extends ChannelSession{
throw new SftpException(SSH_FX_FAILURE, v.toString());
}
else{
dst=(String)(v.elementAt(0));
dst=v.elementAt(0);
}
if(monitor!=null){
@@ -547,9 +544,7 @@ public class ChannelSftp extends ChannelSession{
}
throw (SftpException)e;
}
if(e instanceof Throwable)
throw new SftpException(SSH_FX_FAILURE, e.toString(), (Throwable)e);
throw new SftpException(SSH_FX_FAILURE, e.toString());
throw new SftpException(SSH_FX_FAILURE, e.toString(), e);
}
}
@@ -693,9 +688,7 @@ public class ChannelSftp extends ChannelSession{
}
catch(Exception e){
if(e instanceof SftpException) throw (SftpException)e;
if(e instanceof Throwable)
throw new SftpException(SSH_FX_FAILURE, e.toString(), (Throwable)e);
throw new SftpException(SSH_FX_FAILURE, e.toString());
throw new SftpException(SSH_FX_FAILURE, e.toString(), e);
}
}
@@ -785,11 +778,13 @@ public class ChannelSftp extends ChannelSession{
private int writecount=0;
private Header header=new Header();
public void write(byte[] d) throws java.io.IOException{
@Override
public void write(byte[] d) throws IOException{
write(d, 0, d.length);
}
public void write(byte[] d, int s, int len) throws java.io.IOException{
@Override
public void write(byte[] d, int s, int len) throws IOException{
if(init){
startid=seq;
_ackid=seq;
@@ -830,16 +825,18 @@ public class ChannelSftp extends ChannelSession{
}
}
catch(IOException e){ throw e; }
catch(Exception e){ throw new IOException(e.toString()); }
catch(Exception e){ throw new IOException(e.toString(), e); }
}
byte[] _data=new byte[1];
public void write(int foo) throws java.io.IOException{
@Override
public void write(int foo) throws IOException{
_data[0]=(byte)foo;
write(_data, 0, 1);
}
public void flush() throws java.io.IOException{
@Override
public void flush() throws IOException{
if(isClosed){
throw new IOException("stream already closed");
@@ -855,12 +852,13 @@ public class ChannelSftp extends ChannelSession{
}
}
catch(SftpException e){
throw new IOException(e.toString());
throw new IOException(e.toString(), e);
}
}
}
public void close() throws java.io.IOException{
@Override
public void close() throws IOException{
if(isClosed){
return;
}
@@ -869,7 +867,7 @@ public class ChannelSftp extends ChannelSession{
try{ _sendCLOSE(handle, header); }
catch(IOException e){ throw e; }
catch(Exception e){
throw new IOException(e.toString());
throw new IOException(e.toString(), e);
}
isClosed=true;
}
@@ -878,9 +876,7 @@ public class ChannelSftp extends ChannelSession{
}
catch(Exception e){
if(e instanceof SftpException) throw (SftpException)e;
if(e instanceof Throwable)
throw new SftpException(SSH_FX_FAILURE, "", (Throwable)e);
throw new SftpException(SSH_FX_FAILURE, "");
throw new SftpException(SSH_FX_FAILURE, e.toString(), e);
}
}
@@ -903,7 +899,7 @@ public class ChannelSftp extends ChannelSession{
src=remoteAbsolutePath(src);
dst=localAbsolutePath(dst);
Vector v=glob_remote(src);
Vector<String> v=glob_remote(src);
int vsize=v.size();
if(vsize==0){
throw new SftpException(SSH_FX_NO_SUCH_FILE, "No such file");
@@ -911,12 +907,12 @@ public class ChannelSftp extends ChannelSession{
File dstFile=new File(dst);
boolean isDstDir=dstFile.isDirectory();
StringBuffer dstsb=null;
StringBuilder dstsb=null;
if(isDstDir){
if(!dst.endsWith(file_separator)){
dst+=file_separator;
}
dstsb=new StringBuffer(dst);
dstsb=new StringBuilder(dst);
}
else if(vsize>1){
throw new SftpException(SSH_FX_FAILURE,
@@ -924,7 +920,7 @@ public class ChannelSftp extends ChannelSession{
}
for(int j=0; j<vsize; j++){
String _src=(String)(v.elementAt(j));
String _src=v.elementAt(j);
SftpATTRS attr=_stat(_src);
if(attr.isDir()){
throw new SftpException(SSH_FX_FAILURE,
@@ -938,8 +934,8 @@ public class ChannelSftp extends ChannelSession{
else dstsb.append(_src.substring(i + 1));
_dst=dstsb.toString();
if(_dst.indexOf("..")!=-1){
String dstc = (new java.io.File(dst)).getCanonicalPath();
String _dstc = (new java.io.File(_dst)).getCanonicalPath();
String dstc = (new File(dst)).getCanonicalPath();
String _dstc = (new File(_dst)).getCanonicalPath();
if(!(_dstc.length()>dstc.length() &&
_dstc.substring(0, dstc.length()+1).equals(dstc+file_separator))){
throw new SftpException(SSH_FX_FAILURE,
@@ -999,9 +995,7 @@ public class ChannelSftp extends ChannelSession{
}
}
if(e instanceof SftpException) throw (SftpException)e;
if(e instanceof Throwable)
throw new SftpException(SSH_FX_FAILURE, "", (Throwable)e);
throw new SftpException(SSH_FX_FAILURE, "");
throw new SftpException(SSH_FX_FAILURE, e.toString(), e);
}
}
public void get(String src, OutputStream dst) throws SftpException{
@@ -1031,9 +1025,7 @@ public class ChannelSftp extends ChannelSession{
}
catch(Exception e){
if(e instanceof SftpException) throw (SftpException)e;
if(e instanceof Throwable)
throw new SftpException(SSH_FX_FAILURE, "", (Throwable)e);
throw new SftpException(SSH_FX_FAILURE, "");
throw new SftpException(SSH_FX_FAILURE, e.toString(), e);
}
}
@@ -1180,15 +1172,14 @@ public class ChannelSftp extends ChannelSession{
}
catch(Exception e){
if(e instanceof SftpException) throw (SftpException)e;
if(e instanceof Throwable)
throw new SftpException(SSH_FX_FAILURE, "", (Throwable)e);
throw new SftpException(SSH_FX_FAILURE, "");
throw new SftpException(SSH_FX_FAILURE, e.toString(), e);
}
}
private class RequestQueue {
class OutOfOrderException extends Exception {
private static final long serialVersionUID=-1L;
long offset;
OutOfOrderException(long offset){
this.offset=offset;
@@ -1296,12 +1287,14 @@ public class ChannelSftp extends ChannelSession{
/**
* @deprecated This method will be deleted in the future.
*/
@Deprecated
public InputStream get(String src, int mode) throws SftpException{
return get(src, null, 0L);
}
/**
* @deprecated This method will be deleted in the future.
*/
@Deprecated
public InputStream get(String src, final SftpProgressMonitor monitor, final int mode) throws SftpException{
return get(src, monitor, 0L);
}
@@ -1341,7 +1334,7 @@ public class ChannelSftp extends ChannelSession{
rq.init();
java.io.InputStream in=new java.io.InputStream(){
InputStream in=new InputStream(){
long offset=skip;
boolean closed=false;
int rest_length=0;
@@ -1351,7 +1344,8 @@ public class ChannelSftp extends ChannelSession{
int request_max=1;
long request_offset=offset;
public int read() throws java.io.IOException{
@Override
public int read() throws IOException{
if(closed)return -1;
int i=read(_data, 0, 1);
if (i==-1) { return -1; }
@@ -1359,11 +1353,13 @@ public class ChannelSftp extends ChannelSession{
return _data[0]&0xff;
}
}
public int read(byte[] d) throws java.io.IOException{
@Override
public int read(byte[] d) throws IOException{
if(closed)return -1;
return read(d, 0, d.length);
}
public int read(byte[] d, int s, int len) throws java.io.IOException{
@Override
public int read(byte[] d, int s, int len) throws IOException{
if(closed)return -1;
if(d==null){throw new NullPointerException();}
if(s<0 || len <0 || s+len>d.length){
@@ -1430,7 +1426,7 @@ public class ChannelSftp extends ChannelSession{
return 0;
}
catch(SftpException e){
throw new IOException("error: "+e.toString());
throw new IOException("error: "+e.toString(), e);
}
if(type!=SSH_FXP_STATUS && type!=SSH_FXP_DATA){
@@ -1523,6 +1519,7 @@ public class ChannelSftp extends ChannelSession{
}
return 0; // ??
}
@Override
public void close() throws IOException{
if(closed)return;
closed=true;
@@ -1536,15 +1533,14 @@ public class ChannelSftp extends ChannelSession{
}
catch(Exception e){
if(e instanceof SftpException) throw (SftpException)e;
if(e instanceof Throwable)
throw new SftpException(SSH_FX_FAILURE, "", (Throwable)e);
throw new SftpException(SSH_FX_FAILURE, "");
throw new SftpException(SSH_FX_FAILURE, e.toString(), e);
}
}
public java.util.Vector ls(String path) throws SftpException{
final java.util.Vector v = new Vector();
public Vector<LsEntry> ls(String path) throws SftpException{
final Vector<LsEntry> v = new Vector<>();
LsEntrySelector selector = new LsEntrySelector(){
@Override
public int select(LsEntry entry){
v.addElement(entry);
return CONTINUE;
@@ -1571,7 +1567,7 @@ public class ChannelSftp extends ChannelSession{
path=remoteAbsolutePath(path);
byte[] pattern=null;
java.util.Vector v=new java.util.Vector();
Vector<LsEntry> v=new Vector<>();
int foo=path.lastIndexOf('/');
String dir=path.substring(0, ((foo==0)?1:foo));
@@ -1696,7 +1692,7 @@ public class ChannelSftp extends ChannelSession{
byte[] _filename=filename;
if(!fEncoding_is_utf8){
f=Util.byte2str(_filename, fEncoding);
_filename=Util.str2byte(f, UTF8);
_filename=Util.str2byte(f, StandardCharsets.UTF_8);
}
find=Util.glob(pattern, _filename);
}
@@ -1743,9 +1739,7 @@ public class ChannelSftp extends ChannelSession{
}
catch(Exception e){
if(e instanceof SftpException) throw (SftpException)e;
if(e instanceof Throwable)
throw new SftpException(SSH_FX_FAILURE, "", (Throwable)e);
throw new SftpException(SSH_FX_FAILURE, "");
throw new SftpException(SSH_FX_FAILURE, e.toString(), e);
}
}
@@ -1792,9 +1786,7 @@ public class ChannelSftp extends ChannelSession{
}
catch(Exception e){
if(e instanceof SftpException) throw (SftpException)e;
if(e instanceof Throwable)
throw new SftpException(SSH_FX_FAILURE, "", (Throwable)e);
throw new SftpException(SSH_FX_FAILURE, "");
throw new SftpException(SSH_FX_FAILURE, e.toString(), e);
}
return null;
}
@@ -1845,9 +1837,7 @@ public class ChannelSftp extends ChannelSession{
}
catch(Exception e){
if(e instanceof SftpException) throw (SftpException)e;
if(e instanceof Throwable)
throw new SftpException(SSH_FX_FAILURE, "", (Throwable)e);
throw new SftpException(SSH_FX_FAILURE, "");
throw new SftpException(SSH_FX_FAILURE, e.toString(), e);
}
}
@@ -1897,9 +1887,7 @@ public class ChannelSftp extends ChannelSession{
}
catch(Exception e){
if(e instanceof SftpException) throw (SftpException)e;
if(e instanceof Throwable)
throw new SftpException(SSH_FX_FAILURE, "", (Throwable)e);
throw new SftpException(SSH_FX_FAILURE, "");
throw new SftpException(SSH_FX_FAILURE, e.toString(), e);
}
}
@@ -1917,13 +1905,13 @@ public class ChannelSftp extends ChannelSession{
oldpath=isUnique(oldpath);
Vector v=glob_remote(newpath);
Vector<String> v=glob_remote(newpath);
int vsize=v.size();
if(vsize>=2){
throw new SftpException(SSH_FX_FAILURE, v.toString());
}
if(vsize==1){
newpath=(String)(v.elementAt(0));
newpath=v.elementAt(0);
}
else{ // vsize==0
if(isPattern(newpath))
@@ -1951,9 +1939,7 @@ public class ChannelSftp extends ChannelSession{
}
catch(Exception e){
if(e instanceof SftpException) throw (SftpException)e;
if(e instanceof Throwable)
throw new SftpException(SSH_FX_FAILURE, "", (Throwable)e);
throw new SftpException(SSH_FX_FAILURE, "");
throw new SftpException(SSH_FX_FAILURE, e.toString(), e);
}
}
public void rm(String path) throws SftpException{
@@ -1962,13 +1948,13 @@ public class ChannelSftp extends ChannelSession{
path=remoteAbsolutePath(path);
Vector v=glob_remote(path);
Vector<String> v=glob_remote(path);
int vsize=v.size();
Header header=new Header();
for(int j=0; j<vsize; j++){
path=(String)(v.elementAt(j));
path=v.elementAt(j);
sendREMOVE(Util.str2byte(path, fEncoding));
header=header(buf, header);
@@ -1988,9 +1974,7 @@ public class ChannelSftp extends ChannelSession{
}
catch(Exception e){
if(e instanceof SftpException) throw (SftpException)e;
if(e instanceof Throwable)
throw new SftpException(SSH_FX_FAILURE, "", (Throwable)e);
throw new SftpException(SSH_FX_FAILURE, "");
throw new SftpException(SSH_FX_FAILURE, e.toString(), e);
}
}
@@ -2021,10 +2005,10 @@ public class ChannelSftp extends ChannelSession{
path=remoteAbsolutePath(path);
Vector v=glob_remote(path);
Vector<String> v=glob_remote(path);
int vsize=v.size();
for(int j=0; j<vsize; j++){
path=(String)(v.elementAt(j));
path=v.elementAt(j);
SftpATTRS attr=_stat(path);
@@ -2035,9 +2019,7 @@ public class ChannelSftp extends ChannelSession{
}
catch(Exception e){
if(e instanceof SftpException) throw (SftpException)e;
if(e instanceof Throwable)
throw new SftpException(SSH_FX_FAILURE, "", (Throwable)e);
throw new SftpException(SSH_FX_FAILURE, "");
throw new SftpException(SSH_FX_FAILURE, e.toString(), e);
}
}
@@ -2047,10 +2029,10 @@ public class ChannelSftp extends ChannelSession{
path=remoteAbsolutePath(path);
Vector v=glob_remote(path);
Vector<String> v=glob_remote(path);
int vsize=v.size();
for(int j=0; j<vsize; j++){
path=(String)(v.elementAt(j));
path=v.elementAt(j);
SftpATTRS attr=_stat(path);
@@ -2061,9 +2043,7 @@ public class ChannelSftp extends ChannelSession{
}
catch(Exception e){
if(e instanceof SftpException) throw (SftpException)e;
if(e instanceof Throwable)
throw new SftpException(SSH_FX_FAILURE, "", (Throwable)e);
throw new SftpException(SSH_FX_FAILURE, "");
throw new SftpException(SSH_FX_FAILURE, e.toString(), e);
}
}
@@ -2073,10 +2053,10 @@ public class ChannelSftp extends ChannelSession{
path=remoteAbsolutePath(path);
Vector v=glob_remote(path);
Vector<String> v=glob_remote(path);
int vsize=v.size();
for(int j=0; j<vsize; j++){
path=(String)(v.elementAt(j));
path=v.elementAt(j);
SftpATTRS attr=_stat(path);
@@ -2087,9 +2067,7 @@ public class ChannelSftp extends ChannelSession{
}
catch(Exception e){
if(e instanceof SftpException) throw (SftpException)e;
if(e instanceof Throwable)
throw new SftpException(SSH_FX_FAILURE, "", (Throwable)e);
throw new SftpException(SSH_FX_FAILURE, "");
throw new SftpException(SSH_FX_FAILURE, e.toString(), e);
}
}
@@ -2099,10 +2077,10 @@ public class ChannelSftp extends ChannelSession{
path=remoteAbsolutePath(path);
Vector v=glob_remote(path);
Vector<String> v=glob_remote(path);
int vsize=v.size();
for(int j=0; j<vsize; j++){
path=(String)(v.elementAt(j));
path=v.elementAt(j);
SftpATTRS attr=_stat(path);
@@ -2113,9 +2091,7 @@ public class ChannelSftp extends ChannelSession{
}
catch(Exception e){
if(e instanceof SftpException) throw (SftpException)e;
if(e instanceof Throwable)
throw new SftpException(SSH_FX_FAILURE, "", (Throwable)e);
throw new SftpException(SSH_FX_FAILURE, "");
throw new SftpException(SSH_FX_FAILURE, e.toString(), e);
}
}
@@ -2125,13 +2101,13 @@ public class ChannelSftp extends ChannelSession{
path=remoteAbsolutePath(path);
Vector v=glob_remote(path);
Vector<String> v=glob_remote(path);
int vsize=v.size();
Header header=new Header();
for(int j=0; j<vsize; j++){
path=(String)(v.elementAt(j));
path=v.elementAt(j);
sendRMDIR(Util.str2byte(path, fEncoding));
header=header(buf, header);
@@ -2152,9 +2128,7 @@ public class ChannelSftp extends ChannelSession{
}
catch(Exception e){
if(e instanceof SftpException) throw (SftpException)e;
if(e instanceof Throwable)
throw new SftpException(SSH_FX_FAILURE, "", (Throwable)e);
throw new SftpException(SSH_FX_FAILURE, "");
throw new SftpException(SSH_FX_FAILURE, e.toString(), e);
}
}
@@ -2183,9 +2157,7 @@ public class ChannelSftp extends ChannelSession{
}
catch(Exception e){
if(e instanceof SftpException) throw (SftpException)e;
if(e instanceof Throwable)
throw new SftpException(SSH_FX_FAILURE, "", (Throwable)e);
throw new SftpException(SSH_FX_FAILURE, "");
throw new SftpException(SSH_FX_FAILURE, e.toString(), e);
}
}
@@ -2200,9 +2172,7 @@ public class ChannelSftp extends ChannelSession{
}
catch(Exception e){
if(e instanceof SftpException) throw (SftpException)e;
if(e instanceof Throwable)
throw new SftpException(SSH_FX_FAILURE, "", (Throwable)e);
throw new SftpException(SSH_FX_FAILURE, "");
throw new SftpException(SSH_FX_FAILURE, e.toString(), e);
}
//return null;
}
@@ -2231,9 +2201,7 @@ public class ChannelSftp extends ChannelSession{
}
catch(Exception e){
if(e instanceof SftpException) throw (SftpException)e;
if(e instanceof Throwable)
throw new SftpException(SSH_FX_FAILURE, "", (Throwable)e);
throw new SftpException(SSH_FX_FAILURE, "");
throw new SftpException(SSH_FX_FAILURE, e.toString(), e);
}
//return null;
}
@@ -2253,9 +2221,7 @@ public class ChannelSftp extends ChannelSession{
}
catch(Exception e){
if(e instanceof SftpException) throw (SftpException)e;
if(e instanceof Throwable)
throw new SftpException(SSH_FX_FAILURE, "", (Throwable)e);
throw new SftpException(SSH_FX_FAILURE, "");
throw new SftpException(SSH_FX_FAILURE, e.toString(), e);
}
//return null;
}
@@ -2291,9 +2257,7 @@ public class ChannelSftp extends ChannelSession{
}
catch(Exception e){
if(e instanceof SftpException) throw (SftpException)e;
if(e instanceof Throwable)
throw new SftpException(SSH_FX_FAILURE, "", (Throwable)e);
throw new SftpException(SSH_FX_FAILURE, "");
throw new SftpException(SSH_FX_FAILURE, e.toString(), e);
}
//return null;
}
@@ -2313,9 +2277,7 @@ public class ChannelSftp extends ChannelSession{
}
catch(Exception e){
if(e instanceof SftpException) throw (SftpException)e;
if(e instanceof Throwable)
throw new SftpException(SSH_FX_FAILURE, "", (Throwable)e);
throw new SftpException(SSH_FX_FAILURE, "");
throw new SftpException(SSH_FX_FAILURE, e.toString(), e);
}
}
@@ -2342,9 +2304,7 @@ public class ChannelSftp extends ChannelSession{
}
catch(Exception e){
if(e instanceof SftpException) throw (SftpException)e;
if(e instanceof Throwable)
throw new SftpException(SSH_FX_FAILURE, "", (Throwable)e);
throw new SftpException(SSH_FX_FAILURE, "");
throw new SftpException(SSH_FX_FAILURE, e.toString(), e);
}
}
@@ -2385,18 +2345,16 @@ public class ChannelSftp extends ChannelSession{
path=remoteAbsolutePath(path);
Vector v=glob_remote(path);
Vector<String> v=glob_remote(path);
int vsize=v.size();
for(int j=0; j<vsize; j++){
path=(String)(v.elementAt(j));
path=v.elementAt(j);
_setStat(path, attr);
}
}
catch(Exception e){
if(e instanceof SftpException) throw (SftpException)e;
if(e instanceof Throwable)
throw new SftpException(SSH_FX_FAILURE, "", (Throwable)e);
throw new SftpException(SSH_FX_FAILURE, "");
throw new SftpException(SSH_FX_FAILURE, e.toString(), e);
}
}
private void _setStat(String path, SftpATTRS attr) throws SftpException{
@@ -2420,9 +2378,7 @@ public class ChannelSftp extends ChannelSession{
}
catch(Exception e){
if(e instanceof SftpException) throw (SftpException)e;
if(e instanceof Throwable)
throw new SftpException(SSH_FX_FAILURE, "", (Throwable)e);
throw new SftpException(SSH_FX_FAILURE, "");
throw new SftpException(SSH_FX_FAILURE, e.toString(), e);
}
}
@@ -2439,9 +2395,7 @@ public class ChannelSftp extends ChannelSession{
}
catch(Exception e){
if(e instanceof SftpException) throw (SftpException)e;
if(e instanceof Throwable)
throw new SftpException(SSH_FX_FAILURE, "", (Throwable)e);
throw new SftpException(SSH_FX_FAILURE, "");
throw new SftpException(SSH_FX_FAILURE, e.toString(), e);
}
}
return home;
@@ -2675,8 +2629,8 @@ public class ChannelSftp extends ChannelSession{
putHEAD(buf, type, length);
}
private Vector glob_remote(String _path) throws Exception{
Vector v=new Vector();
private Vector<String> glob_remote(String _path) throws Exception{
Vector<String> v=new Vector<>();
int i=0;
int foo=_path.lastIndexOf('/');
@@ -2768,7 +2722,7 @@ public class ChannelSftp extends ChannelSession{
if(!fEncoding_is_utf8){
f=Util.byte2str(filename, fEncoding);
_filename=Util.str2byte(f, UTF8);
_filename=Util.str2byte(f, StandardCharsets.UTF_8);
}
found=Util.glob(pattern, _filename);
@@ -2805,10 +2759,10 @@ public class ChannelSftp extends ChannelSession{
return false;
}
private Vector glob_local(String _path) throws Exception{
private Vector<String> glob_local(String _path) throws Exception{
//System.err.println("glob_local: "+_path);
Vector v=new Vector();
byte[] path=Util.str2byte(_path, UTF8);
Vector<String> v=new Vector<>();
byte[] path=Util.str2byte(_path, StandardCharsets.UTF_8);
int i=path.length-1;
while(i>=0){
if(path[i]!='*' && path[i]!='?'){
@@ -2851,11 +2805,11 @@ public class ChannelSftp extends ChannelSession{
//System.err.println("dir: "+new String(dir)+" pattern: "+new String(pattern));
try{
String[] children=(new File(Util.byte2str(dir, UTF8))).list();
String[] children=(new File(Util.byte2str(dir, StandardCharsets.UTF_8))).list();
String pdir=Util.byte2str(dir)+file_separator;
for(int j=0; j<children.length; j++){
//System.err.println("children: "+children[j]);
if(Util.glob(pattern, Util.str2byte(children[j], UTF8))){
if(Util.glob(pattern, Util.str2byte(children[j], StandardCharsets.UTF_8))){
v.addElement(pdir+children[j]);
}
}
@@ -2870,7 +2824,7 @@ public class ChannelSftp extends ChannelSession{
buf.getLength()>=4){ // SSH_FXP_STATUS packet.
byte[] str=buf.getString();
//byte[] tag=buf.getString();
throw new SftpException(i, Util.byte2str(str, UTF8));
throw new SftpException(i, Util.byte2str(str, StandardCharsets.UTF_8));
}
else{
throw new SftpException(i, "Failure");
@@ -2881,12 +2835,13 @@ public class ChannelSftp extends ChannelSession{
return (new File(path)).isAbsolute();
}
@Override
public void disconnect(){
super.disconnect();
}
private boolean isPattern(String path, byte[][] utf8){
byte[] _path=Util.str2byte(path, UTF8);
byte[] _path=Util.str2byte(path, StandardCharsets.UTF_8);
if(utf8!=null)
utf8[0]=_path;
return isPattern(_path);
@@ -2925,7 +2880,7 @@ public class ChannelSftp extends ChannelSession{
}
}
class Header{
static class Header{
int length;
int type;
int rid;
@@ -2960,11 +2915,11 @@ public class ChannelSftp extends ChannelSession{
* @return the returned string is unquoted.
*/
private String isUnique(String path) throws SftpException, Exception{
Vector v=glob_remote(path);
Vector<String> v=glob_remote(path);
if(v.size()!=1){
throw new SftpException(SSH_FX_FAILURE, path+" is not unique: "+v.toString());
}
return (String)(v.elementAt(0));
return v.elementAt(0);
}
public int getServerVersion() throws SftpException{
@@ -2974,24 +2929,26 @@ public class ChannelSftp extends ChannelSession{
return server_version;
}
@Deprecated
public void setFilenameEncoding(String encoding) throws SftpException{
int sversion=getServerVersion();
if(3 <= sversion && sversion <= 5 &&
!encoding.equals(UTF8)){
throw new SftpException(SSH_FX_FAILURE,
"The encoding can not be changed for this sftp server.");
try{
setFilenameEncoding(Charset.forName(encoding));
}
if(encoding.equals(UTF8)){
encoding=UTF8;
catch(Exception e){
if(e instanceof SftpException) throw (SftpException)e;
throw new SftpException(SSH_FX_FAILURE, e.toString(), e);
}
}
public void setFilenameEncoding(Charset encoding){
fEncoding=encoding;
fEncoding_is_utf8=fEncoding.equals(UTF8);
fEncoding_is_utf8=fEncoding.equals(StandardCharsets.UTF_8);
}
public String getExtension(String key){
if(extensions==null)
return null;
return (String)extensions.get(key);
return extensions.get(key);
}
public String realpath(String path) throws SftpException{
@@ -3001,13 +2958,11 @@ public class ChannelSftp extends ChannelSession{
}
catch(Exception e){
if(e instanceof SftpException) throw (SftpException)e;
if(e instanceof Throwable)
throw new SftpException(SSH_FX_FAILURE, "", (Throwable)e);
throw new SftpException(SSH_FX_FAILURE, "");
throw new SftpException(SSH_FX_FAILURE, e.toString(), e);
}
}
public class LsEntry implements Comparable{
public static class LsEntry implements Comparable<LsEntry>{
private String filename;
private String longname;
private SftpATTRS attrs;
@@ -3022,12 +2977,11 @@ public class ChannelSftp extends ChannelSession{
void setLongname(String longname){this.longname = longname;};
public SftpATTRS getAttrs(){return attrs;};
void setAttrs(SftpATTRS attrs) {this.attrs = attrs;};
@Override
public String toString(){ return longname; }
public int compareTo(Object o) throws ClassCastException{
if(o instanceof LsEntry){
return filename.compareTo(((LsEntry)o).getFilename());
}
throw new ClassCastException("a decendent of LsEntry must be given.");
@Override
public int compareTo(LsEntry o){
return filename.compareTo(o.getFilename());
}
}

View File

@@ -38,6 +38,7 @@ public class ChannelShell extends ChannelSession{
pty=true;
}
@Override
public void start() throws JSchException{
Session _session=getSession();
try{
@@ -48,13 +49,11 @@ public class ChannelShell extends ChannelSession{
}
catch(Exception e){
if(e instanceof JSchException) throw (JSchException)e;
if(e instanceof Throwable)
throw new JSchException("ChannelShell", (Throwable)e);
throw new JSchException("ChannelShell");
throw new JSchException("ChannelShell", e);
}
if(io.in!=null){
thread=new Thread(this);
thread=new Thread(this::run);
thread.setName("Shell for "+_session.host);
if(_session.daemon_thread){
thread.setDaemon(_session.daemon_thread);
@@ -63,6 +62,7 @@ public class ChannelShell extends ChannelSession{
}
}
@Override
void init() throws JSchException {
io.setInputStream(getSession().in);
io.setOutputStream(getSession().out);

View File

@@ -29,15 +29,14 @@ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package com.jcraft.jsch;
import java.io.*;
public class ChannelSubsystem extends ChannelSession{
boolean xforwading=false;
boolean pty=false;
boolean want_reply=true;
String subsystem="";
public void setXForwarding(boolean foo){ xforwading=foo; }
public void setPty(boolean foo){ pty=foo; }
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{
@@ -55,12 +54,10 @@ public class ChannelSubsystem extends ChannelSession{
}
catch(Exception e){
if(e instanceof JSchException){ throw (JSchException)e; }
if(e instanceof Throwable)
throw new JSchException("ChannelSubsystem", (Throwable)e);
throw new JSchException("ChannelSubsystem");
throw new JSchException("ChannelSubsystem", e);
}
if(io.in!=null){
thread=new Thread(this);
thread=new Thread(this::run);
thread.setName("Subsystem for "+_session.host);
if(_session.daemon_thread){
thread.setDaemon(_session.daemon_thread);
@@ -69,15 +66,16 @@ public class ChannelSubsystem extends ChannelSession{
}
}
@Override
void init() throws JSchException {
io.setInputStream(getSession().in);
io.setOutputStream(getSession().out);
}
public void setErrStream(java.io.OutputStream out){
public void setErrStream(OutputStream out){
setExtOutputStream(out);
}
public java.io.InputStream getErrStream() throws java.io.IOException {
public InputStream getErrStream() throws IOException {
return getExtInputStream();
}
}

View File

@@ -29,7 +29,9 @@ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package com.jcraft.jsch;
import java.io.IOException;
import java.net.*;
import java.util.Hashtable;
class ChannelX11 extends Channel{
@@ -46,8 +48,8 @@ class ChannelX11 extends Channel{
static byte[] cookie=null;
private static byte[] cookie_hex=null;
private static java.util.Hashtable faked_cookie_pool=new java.util.Hashtable();
private static java.util.Hashtable faked_cookie_hex_pool=new java.util.Hashtable();
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};
@@ -72,7 +74,7 @@ class ChannelX11 extends Channel{
static void setPort(int foo){ port=foo; }
static byte[] getFakedCookie(Session session){
synchronized(faked_cookie_hex_pool){
byte[] foo=(byte[])faked_cookie_hex_pool.get(session);
byte[] foo=faked_cookie_hex_pool.get(session);
if(foo==null){
Random random=Session.random;
foo=new byte[16];
@@ -130,7 +132,8 @@ System.err.println("");
*/
}
public void run(){
@Override
void run(){
try{
socket=Util.createSocket(host, port, TIMEOUT);
@@ -187,7 +190,8 @@ System.err.println("");
return cache;
}
void write(byte[] foo, int s, int l) throws java.io.IOException {
@Override
void write(byte[] foo, int s, int l) throws IOException {
//if(eof_local)return;
if(init){
@@ -197,7 +201,7 @@ System.err.println("");
_session=getSession();
}
catch(JSchException e){
throw new java.io.IOException(e.toString());
throw new IOException(e.toString(), e);
}
foo=addCache(foo, s, l);
@@ -228,7 +232,7 @@ System.err.println("");
byte[] faked_cookie=null;
synchronized(faked_cookie_pool){
faked_cookie=(byte[])faked_cookie_pool.get(_session);
faked_cookie=faked_cookie_pool.get(_session);
}
/*

View File

@@ -34,7 +34,13 @@ public interface Cipher{
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;}
}

View File

@@ -29,14 +29,19 @@ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package com.jcraft.jsch;
public class CipherNone implements Cipher{
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; }
}

View File

@@ -32,6 +32,13 @@ package com.jcraft.jsch;
public interface Compression{
static public final int INFLATER=0;
static public 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);

View File

@@ -42,14 +42,20 @@ public interface ConfigRepository {
}
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; }
};
}

View File

@@ -0,0 +1,38 @@
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
/*
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;
}
}

View File

@@ -0,0 +1,38 @@
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
/*
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;
}
}

View File

@@ -29,7 +29,7 @@ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package com.jcraft.jsch;
public class DHEC256 extends DHECN {
class DHEC256 extends DHECN {
public DHEC256(){
sha_name="sha-256";
key_size=256;

View File

@@ -29,7 +29,7 @@ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package com.jcraft.jsch;
public class DHEC384 extends DHECN {
class DHEC384 extends DHECN {
public DHEC384(){
sha_name="sha-384";
key_size=384;

View File

@@ -29,7 +29,7 @@ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package com.jcraft.jsch;
public class DHEC521 extends DHECN {
class DHEC521 extends DHECN {
public DHEC521(){
sha_name="sha-512";
key_size=521;

View File

@@ -29,7 +29,7 @@ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package com.jcraft.jsch;
public abstract class DHECN extends KeyExchange{
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;
@@ -52,17 +52,17 @@ public abstract class DHECN extends KeyExchange{
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.session=session;
this.V_S=V_S;
this.V_C=V_C;
this.I_S=I_S;
this.I_C=I_C;
try{
Class c=Class.forName(session.getConfig(sha_name));
sha=(HASH)(c.newInstance());
Class<? extends HASH> c=Class.forName(session.getConfig(sha_name)).asSubclass(HASH.class);
sha=c.getDeclaredConstructor().newInstance();
sha.init();
}
catch(Exception e){
@@ -76,17 +76,15 @@ public abstract class DHECN extends KeyExchange{
buf.putByte((byte)SSH_MSG_KEX_ECDH_INIT);
try{
Class c=Class.forName(session.getConfig("ecdh-sha2-nistp"));
ecdh=(ECDH)(c.newInstance());
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){
if(e instanceof Throwable)
throw new JSchException(e.toString(), (Throwable)e);
throw new JSchException(e.toString());
throw new JSchException(e.toString(), e);
}
if(V_S==null){ // This is a really ugly hack for Session.checkKexes ;-(
@@ -95,16 +93,17 @@ public abstract class DHECN extends KeyExchange{
session.write(packet);
if(JSch.getLogger().isEnabled(Logger.INFO)){
JSch.getLogger().log(Logger.INFO,
if(session.getLogger().isEnabled(Logger.INFO)){
session.getLogger().log(Logger.INFO,
"SSH_MSG_KEX_ECDH_INIT sent");
JSch.getLogger().log(Logger.INFO,
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){
@@ -117,8 +116,8 @@ public abstract class DHECN extends KeyExchange{
j=_buf.getInt();
j=_buf.getByte();
j=_buf.getByte();
if(j!=31){
System.err.println("type: must be 31 "+j);
if(j!=SSH_MSG_KEX_ECDH_REPLY){
System.err.println("type: must be SSH_MSG_KEX_ECDH_REPLY "+j);
return false;
}
@@ -183,5 +182,6 @@ public abstract class DHECN extends KeyExchange{
return false;
}
@Override
public int getState(){return state; }
}

View File

@@ -29,7 +29,7 @@ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package com.jcraft.jsch;
public class DHG1 extends KeyExchange{
class DHG1 extends DHGN{
static final byte[] g={ 2 };
static final byte[] p={
@@ -52,145 +52,10 @@ public class DHG1 extends KeyExchange{
(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF
};
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;
public void init(Session session,
byte[] V_S, byte[] V_C, byte[] I_S, byte[] I_C) throws Exception{
this.session=session;
this.V_S=V_S;
this.V_C=V_C;
this.I_S=I_S;
this.I_C=I_C;
try{
Class c=Class.forName(session.getConfig("sha-1"));
sha=(HASH)(c.newInstance());
sha.init();
}
catch(Exception e){
System.err.println(e);
}
buf=new Buffer();
packet=new Packet(buf);
try{
Class c=Class.forName(session.getConfig("dh"));
dh=(DH)(c.newInstance());
dh.init();
}
catch(Exception e){
//System.err.println(e);
throw 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);
session.write(packet);
if(JSch.getLogger().isEnabled(Logger.INFO)){
JSch.getLogger().log(Logger.INFO,
"SSH_MSG_KEXDH_INIT sent");
JSch.getLogger().log(Logger.INFO,
"expecting SSH_MSG_KEXDH_REPLY");
}
state=SSH_MSG_KEXDH_REPLY;
}
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!=31){
System.err.println("type: must be 31 "+j);
return false;
}
K_S=_buf.getString();
byte[] f=_buf.getMPInt();
byte[] sig_of_H=_buf.getString();
dh.setF(f);
dh.checkRange();
K=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);
buf.putMPInt(K);
byte[] foo=new byte[buf.getLength()];
buf.getByte(foo);
sha.update(foo, 0, foo.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;
}
public int getState(){return state; }
@Override
byte[] G(){ return g; }
@Override
byte[] P(){ return p; }
@Override
String sha_name(){ return "sha-1"; }
}

View File

@@ -29,187 +29,8 @@ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package com.jcraft.jsch;
public class DHG14 extends KeyExchange{
class DHG14 extends DHG14N{
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
};
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;
public void init(Session session,
byte[] V_S, byte[] V_C, byte[] I_S, byte[] I_C) throws Exception{
this.session=session;
this.V_S=V_S;
this.V_C=V_C;
this.I_S=I_S;
this.I_C=I_C;
try{
Class c=Class.forName(session.getConfig("sha-1"));
sha=(HASH)(c.newInstance());
sha.init();
}
catch(Exception e){
System.err.println(e);
}
buf=new Buffer();
packet=new Packet(buf);
try{
Class c=Class.forName(session.getConfig("dh"));
dh=(DH)(c.newInstance());
dh.init();
}
catch(Exception e){
//System.err.println(e);
throw 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(JSch.getLogger().isEnabled(Logger.INFO)){
JSch.getLogger().log(Logger.INFO,
"SSH_MSG_KEXDH_INIT sent");
JSch.getLogger().log(Logger.INFO,
"expecting SSH_MSG_KEXDH_REPLY");
}
state=SSH_MSG_KEXDH_REPLY;
}
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!=31){
System.err.println("type: must be 31 "+j);
return false;
}
K_S=_buf.getString();
byte[] f=_buf.getMPInt();
byte[] sig_of_H=_buf.getString();
dh.setF(f);
dh.checkRange();
K=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);
buf.putMPInt(K);
byte[] foo=new byte[buf.getLength()];
buf.getByte(foo);
sha.update(foo, 0, foo.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;
}
public int getState(){return state; }
@Override
String sha_name(){ return "sha-1"; }
}

View File

@@ -0,0 +1,36 @@
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
/*
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"; }
}

View File

@@ -0,0 +1,36 @@
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
/*
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"; }
}

View File

@@ -0,0 +1,75 @@
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
/*
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; }
}

View File

@@ -0,0 +1,36 @@
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
/*
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"; }
}

View File

@@ -0,0 +1,36 @@
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
/*
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"; }
}

View File

@@ -0,0 +1,36 @@
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
/*
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"; }
}

View File

@@ -0,0 +1,91 @@
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
/*
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; }
}

View File

@@ -0,0 +1,36 @@
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
/*
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"; }
}

View File

@@ -0,0 +1,36 @@
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
/*
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"; }
}

View File

@@ -0,0 +1,107 @@
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
/*
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; }
}

View File

@@ -0,0 +1,141 @@
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
/*
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"; }
}

View File

@@ -0,0 +1,173 @@
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
/*
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"; }
}

View File

@@ -29,16 +29,16 @@ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package com.jcraft.jsch;
public class DHGEX extends KeyExchange{
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;
static int min=1024;
static int preferred=1024;
int max=1024;
int min;
int preferred;
int max;
private int state;
@@ -56,19 +56,19 @@ public class DHGEX extends KeyExchange{
private byte[] g;
private byte[] e;
protected String hash="sha-1";
protected String hash;
@Override
public void init(Session session,
byte[] V_S, byte[] V_C, byte[] I_S, byte[] I_C) throws Exception{
this.session=session;
this.V_S=V_S;
this.V_C=V_C;
this.I_S=I_S;
this.I_C=I_C;
try{
Class c=Class.forName(session.getConfig(hash));
sha=(HASH)(c.newInstance());
Class<? extends HASH> c=Class.forName(session.getConfig(hash)).asSubclass(HASH.class);
sha=c.getDeclaredConstructor().newInstance();
sha.init();
}
catch(Exception e){
@@ -79,11 +79,14 @@ public class DHGEX extends KeyExchange{
packet=new Packet(buf);
try{
Class c=Class.forName(session.getConfig("dh"));
// Since JDK8, SunJCE has lifted the keysize restrictions
// from 1024 to 2048 for DH.
preferred = max = check2048(c, max);
dh=(com.jcraft.jsch.DH)(c.newInstance());
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(checkInvalidSize(min) || checkInvalidSize(max) || checkInvalidSize(preferred) || preferred < min || max < preferred){
throw new JSchException("Invalid DHGEX sizes: min=" + min + " max=" + max + " preferred=" + preferred);
}
dh=c.getDeclaredConstructor().newInstance();
dh.init();
}
catch(Exception e){
@@ -97,16 +100,17 @@ public class DHGEX extends KeyExchange{
buf.putInt(max);
session.write(packet);
if(JSch.getLogger().isEnabled(Logger.INFO)){
JSch.getLogger().log(Logger.INFO,
if(session.getLogger().isEnabled(Logger.INFO)){
session.getLogger().log(Logger.INFO,
"SSH_MSG_KEX_DH_GEX_REQUEST("+min+"<"+preferred+"<"+max+") sent");
JSch.getLogger().log(Logger.INFO,
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){
@@ -139,10 +143,10 @@ public class DHGEX extends KeyExchange{
buf.putMPInt(e);
session.write(packet);
if(JSch.getLogger().isEnabled(Logger.INFO)){
JSch.getLogger().log(Logger.INFO,
if(session.getLogger().isEnabled(Logger.INFO)){
session.getLogger().log(Logger.INFO,
"SSH_MSG_KEX_DH_GEX_INIT sent");
JSch.getLogger().log(Logger.INFO,
session.getLogger().log(Logger.INFO,
"expecting SSH_MSG_KEX_DH_GEX_REPLY");
}
@@ -224,22 +228,10 @@ public class DHGEX extends KeyExchange{
return false;
}
@Override
public int getState(){return state; }
protected int check2048(Class c, int _max) throws Exception {
DH dh=(com.jcraft.jsch.DH)(c.newInstance());
dh.init();
byte[] foo = new byte[257];
foo[1]=(byte)0xdd;
foo[256]=0x73;
dh.setP(foo);
byte[] bar = {(byte)0x02};
dh.setG(bar);
try {
dh.getE();
_max=2048;
}
catch(Exception e){ }
return _max;
static boolean checkInvalidSize(int size) {
return (size < 1024 || size > 8192 || size % 1024 != 0);
}
}

View File

@@ -1,6 +1,6 @@
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
/*
Copyright (c) 2006-2016 ymnk, JCraft,Inc. All rights reserved.
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:
@@ -27,11 +27,10 @@ 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.jgss;
import com.jcraft.jsch.JSchException;
public class GSSContextKrb5 {
package com.jcraft.jsch;
class DHGEX1 extends DHGEX {
DHGEX1(){
hash="sha-1";
}
}

View File

@@ -0,0 +1,36 @@
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
/*
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";
}
}

View File

@@ -29,7 +29,7 @@ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package com.jcraft.jsch;
public class DHGEX256 extends DHGEX {
class DHGEX256 extends DHGEX {
DHGEX256(){
hash="sha-256";
}

View File

@@ -0,0 +1,36 @@
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
/*
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";
}
}

View File

@@ -0,0 +1,36 @@
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
/*
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";
}
}

View File

@@ -0,0 +1,184 @@
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
/*
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){
System.err.println(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){
//System.err.println(e);
throw 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!=31){
System.err.println("type: must be 31 "+j);
return false;
}
K_S=_buf.getString();
byte[] f=_buf.getMPInt();
byte[] sig_of_H=_buf.getString();
dh.setF(f);
dh.checkRange();
K=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);
buf.putMPInt(K);
byte[] foo=new byte[buf.getLength()];
buf.getByte(foo);
sha.update(foo, 0, foo.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; }
}

View File

@@ -0,0 +1,200 @@
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
/*
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){
System.err.println(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){
System.err.println("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 = xdh.getSecret(Q_S);
K=normalize(K);
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);
buf.putMPInt(K);
byte[] foo=new byte[buf.getLength()];
buf.getByte(foo);
sha.update(foo, 0, foo.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; }
}

View File

@@ -34,4 +34,5 @@ public interface HASH{
int getBlockSize();
void update(byte[] foo, int start, int len) throws Exception;
byte[] digest() throws Exception;
default String name() {return "";}
}

View File

@@ -36,16 +36,20 @@ public class HostKey{
Util.str2byte("ssh-rsa"),
Util.str2byte("ecdsa-sha2-nistp256"),
Util.str2byte("ecdsa-sha2-nistp384"),
Util.str2byte("ecdsa-sha2-nistp521")
Util.str2byte("ecdsa-sha2-nistp521"),
Util.str2byte("ssh-ed25519"),
Util.str2byte("ssh-ed448")
};
protected static final int GUESS=0;
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;
static final int UNKNOWN=6;
public static final int ED25519=6;
public static final int ED448=7;
protected String marker;
protected String host;
@@ -69,6 +73,8 @@ public class HostKey{
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; }
@@ -85,6 +91,8 @@ public class HostKey{
public String getType(){
if(type==SSHDSS ||
type==SSHRSA ||
type==ED25519 ||
type==ED448 ||
type==ECDSA256 ||
type==ECDSA384 ||
type==ECDSA521){
@@ -101,16 +109,17 @@ public class HostKey{
return UNKNOWN;
}
public String getKey(){
return Util.byte2str(Util.toBase64(key, 0, key.length));
return Util.byte2str(Util.toBase64(key, 0, key.length, true));
}
public String getFingerPrint(JSch jsch){
HASH hash=null;
try{
Class c=Class.forName(jsch.getConfig("md5"));
hash=(HASH)(c.newInstance());
String _c=JSch.getConfig("FingerprintHash").toLowerCase();
Class<? extends HASH> c=Class.forName(JSch.getConfig(_c)).asSubclass(HASH.class);
hash=c.getDeclaredConstructor().newInstance();
}
catch(Exception e){ System.err.println("getFingerPrint: "+e); }
return Util.getFingerPrint(hash, key);
return Util.getFingerPrint(hash, key, false, true);
}
public String getComment(){ return comment; }
public String getMarker(){ return marker; }

View File

@@ -30,8 +30,9 @@ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package com.jcraft.jsch;
import java.io.*;
import java.net.SocketException;
public class IO{
class IO{
InputStream in;
OutputStream out;
OutputStream out_ext;
@@ -56,7 +57,7 @@ public class IO{
setInputStream(in);
}
public void put(Packet p) throws IOException, java.net.SocketException {
void put(Packet p) throws IOException, SocketException {
out.write(p.buffer.buffer, 0, p.buffer.index);
out.flush();
}
@@ -97,7 +98,7 @@ public class IO{
catch(Exception ee){}
}
public void close(){
void close(){
try{
if(in!=null && !in_dontclose) in.close();
in=null;
@@ -114,7 +115,7 @@ public class IO{
}
/*
public void finalize() throws Throwable{
void finalize() throws Throwable{
try{
if(in!=null) in.close();
}

View File

@@ -34,7 +34,7 @@ public interface Identity{
/**
* Decrypts this identity with the specified pass-phrase.
* @param passphrase the pass-phrase for this identity.
* @return <tt>true</tt> if the decryption is succeeded
* @return <code>true</code> if the decryption is succeeded
* or this identity is not cyphered.
*/
public boolean setPassphrase(byte[] passphrase) throws JSchException;
@@ -47,15 +47,49 @@ public interface Identity{
/**
* 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.
* </p>
* @param data data to be signed
* @return the signature
* @see #getSignature(byte[], String)
*/
public byte[] getSignature(byte[] data);
/**
* @deprecated The decryption should be done automatically in #setPassphase(byte[] passphrase)
* @see #setPassphrase(byte[] passphrase)
* 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>
* <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.
* </p>
* @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);}
/**
* @deprecated The decryption should be done automatically in {@link #setPassphrase(byte[])}
* @see #setPassphrase(byte[])
*/
@Deprecated
public boolean decrypt();
/**
@@ -71,8 +105,8 @@ public interface Identity{
public String getName();
/**
* Returns <tt>true</tt> if this identity is cyphered.
* @return <tt>true</tt> if this identity is cyphered.
* Returns <code>true</code> if this identity is cyphered.
* @return <code>true</code> if this identity is cyphered.
*/
public boolean isEncrypted();

View File

@@ -56,9 +56,10 @@ class IdentityFile implements Identity{
/**
* Decrypts this identity with the specified pass-phrase.
* @param passphrase the pass-phrase for this identity.
* @return <tt>true</tt> if the decryption is succeeded
* @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);
}
@@ -67,6 +68,7 @@ class IdentityFile implements Identity{
* Returns the public-key blob.
* @return the public-key blob
*/
@Override
public byte[] getPublicKeyBlob(){
return kpair.getPublicKeyBlob();
}
@@ -76,14 +78,28 @@ class IdentityFile implements Identity{
* @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);
}
/**
* @deprecated This method should not be invoked.
* @see #setPassphrase(byte[] passphrase)
*/
@Override
@Deprecated
public boolean decrypt(){
throw new RuntimeException("not implemented");
}
@@ -92,28 +108,26 @@ class IdentityFile implements Identity{
* Returns the name of the key algorithm.
* @return "ssh-rsa" or "ssh-dss"
*/
@Override
public String getAlgName(){
byte[] name = kpair.getKeyTypeName();
try {
return new String(name, "UTF-8");
}
catch (UnsupportedEncodingException e){
return new String(name);
}
return Util.byte2str(name);
}
/**
* Returns the name of this identity.
* It will be useful to identify this object in the {@link IdentityRepository}.
*/
@Override
public String getName(){
return identity;
}
/**
* Returns <tt>true</tt> if this identity is cyphered.
* @return <tt>true</tt> if this identity is cyphered.
* 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();
}
@@ -121,6 +135,7 @@ class IdentityFile implements Identity{
/**
* Disposes internally allocated data, like byte array for the private key.
*/
@Override
public void clear(){
kpair.dispose();
kpair = null;

View File

@@ -37,79 +37,8 @@ public interface IdentityRepository {
public static final int RUNNING=2;
public String getName();
public int getStatus();
public Vector getIdentities();
public Vector<Identity> getIdentities();
public boolean add(byte[] identity);
public boolean remove(byte[] blob);
public void removeAll();
/**
* 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.
*/
static class Wrapper implements IdentityRepository {
private IdentityRepository ir;
private Vector cache = new Vector();
private boolean keep_in_cache = false;
Wrapper(IdentityRepository ir){
this(ir, false);
}
Wrapper(IdentityRepository ir, boolean keep_in_cache){
this.ir = ir;
this.keep_in_cache = keep_in_cache;
}
public String getName() {
return ir.getName();
}
public int getStatus() {
return ir.getStatus();
}
public boolean add(byte[] identity) {
return ir.add(identity);
}
public boolean remove(byte[] blob) {
return ir.remove(blob);
}
public void removeAll() {
cache.removeAllElements();
ir.removeAll();
}
public Vector getIdentities() {
Vector result = new Vector();
for(int i = 0; i< cache.size(); i++){
Identity identity = (Identity)(cache.elementAt(i));
result.add(identity);
}
Vector 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);
}
}
}
}
}

View File

@@ -0,0 +1,109 @@
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
/*
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);
}
}
}
}

View File

@@ -30,42 +30,76 @@ 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 = "0.1.54";
public static final String VERSION = Version.getVersion();
static java.util.Hashtable config=new java.util.Hashtable();
static Hashtable<String, String> config=new Hashtable<>();
static{
config.put("kex", "ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group14-sha1,diffie-hellman-group-exchange-sha256,diffie-hellman-group-exchange-sha1,diffie-hellman-group1-sha1");
config.put("server_host_key", "ssh-rsa,ssh-dss,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521");
config.put("cipher.s2c",
"aes128-ctr,aes128-cbc,3des-ctr,3des-cbc,blowfish-cbc,aes192-ctr,aes192-cbc,aes256-ctr,aes256-cbc");
config.put("cipher.c2s",
"aes128-ctr,aes128-cbc,3des-ctr,3des-cbc,blowfish-cbc,aes192-ctr,aes192-cbc,aes256-ctr,aes256-cbc");
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_server_sig_algs", Util.getSystemProperty("jsch.enable_server_sig_algs", "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("mac.s2c", "hmac-md5,hmac-sha1,hmac-sha2-256,hmac-sha1-96,hmac-md5-96");
config.put("mac.c2s", "hmac-md5,hmac-sha1,hmac-sha2-256,hmac-sha1-96,hmac-md5-96");
config.put("compression.s2c", "none");
config.put("compression.c2s", "none");
config.put("lang.s2c", Util.getSystemProperty("jsch.lang", ""));
config.put("lang.c2s", Util.getSystemProperty("jsch.lang", ""));
config.put("lang.s2c", "");
config.put("lang.c2s", "");
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", "6");
config.put("compression_level", Util.getSystemProperty("jsch.compression_level", "6"));
config.put("diffie-hellman-group-exchange-sha1",
"com.jcraft.jsch.DHGEX");
"com.jcraft.jsch.DHGEX1");
config.put("diffie-hellman-group1-sha1",
"com.jcraft.jsch.DHG1");
config.put("diffie-hellman-group14-sha1",
"com.jcraft.jsch.DHG14"); // available since JDK8.
"com.jcraft.jsch.DHG14");
config.put("diffie-hellman-group-exchange-sha256",
"com.jcraft.jsch.DHGEX256"); // available since JDK1.4.2.
// On JDK8, 2048bits will be used.
"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");
@@ -76,39 +110,85 @@ public class JSch{
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("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");
// The "hmac-sha2-512" will require the key-length 2048 for DH,
// but Sun's JCE has not allowed to use such a long key.
//config.put("hmac-sha2-512", "com.jcraft.jsch.jce.HMACSHA512");
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("signature.rsa", "com.jcraft.jsch.jce.SignatureRSA");
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");
@@ -120,25 +200,46 @@ public class JSch{
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.jcraft.Compression");
config.put("zlib@openssh.com", "com.jcraft.jsch.jcraft.Compression");
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");
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("StrictHostKeyChecking", "ask");
config.put("HashKnownHosts", "no");
config.put("PreferredAuthentications", "gssapi-with-mic,publickey,keyboard-interactive,password");
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("CheckCiphers", "aes256-ctr,aes192-ctr,aes128-ctr,aes256-cbc,aes192-cbc,aes128-cbc,3des-ctr,arcfour,arcfour128,arcfour256");
config.put("CheckKexes", "diffie-hellman-group14-sha1,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521");
config.put("CheckSignatures", "ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521");
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", "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", "6");
config.put("MaxAuthTries", Util.getSystemProperty("jsch.max_auth_tries", "6"));
config.put("ClearAllForwardings", "no");
}
private java.util.Vector sessionPool = new java.util.Vector();
private Vector<Session> sessionPool = new Vector<>();
private IdentityRepository defaultIdentityRepository =
new LocalIdentityRepository(this);
@@ -179,28 +280,16 @@ public class JSch{
private HostKeyRepository known_hosts=null;
private static final Logger DEVNULL=new Logger(){
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;
private Logger instLogger;
public JSch(){
/*
// The JCE of Sun's Java5 on Mac OS X has the resource leak bug
// in calculating HMAC, so we need to use our own implementations.
try{
String osname=(String)(System.getProperties().get("os.name"));
if(osname!=null && osname.equals("Mac OS X")){
config.put("hmac-sha1", "com.jcraft.jsch.jcraft.HMACSHA1");
config.put("hmac-md5", "com.jcraft.jsch.jcraft.HMACMD5");
config.put("hmac-md5-96", "com.jcraft.jsch.jcraft.HMACMD596");
config.put("hmac-sha1-96", "com.jcraft.jsch.jcraft.HMACSHA196");
}
}
catch(Exception e){
}
*/
}
/**
@@ -474,21 +563,22 @@ public class JSch{
}
else {
synchronized(this){
if(!(identityRepository instanceof IdentityRepository.Wrapper)){
setIdentityRepository(new IdentityRepository.Wrapper(identityRepository));
if(!(identityRepository instanceof IdentityRepositoryWrapper)){
setIdentityRepository(new IdentityRepositoryWrapper(identityRepository));
}
}
((IdentityRepository.Wrapper)identityRepository).add(identity);
((IdentityRepositoryWrapper)identityRepository).add(identity);
}
}
/**
* @deprecated use #removeIdentity(Identity identity)
*/
@Deprecated
public void removeIdentity(String name) throws JSchException{
Vector identities = identityRepository.getIdentities();
Vector<Identity> identities = identityRepository.getIdentities();
for(int i=0; i<identities.size(); i++){
Identity identity=(Identity)(identities.elementAt(i));
Identity identity=identities.elementAt(i);
if(!identity.getName().equals(name))
continue;
if(identityRepository instanceof LocalIdentityRepository){
@@ -517,11 +607,11 @@ public class JSch{
*
* @throws JSchException if identityReposory has problems.
*/
public Vector getIdentityNames() throws JSchException{
Vector foo=new Vector();
Vector identities = identityRepository.getIdentities();
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=(Identity)(identities.elementAt(i));
Identity identity=identities.elementAt(i);
foo.addElement(identity.getName());
}
return foo;
@@ -544,7 +634,10 @@ public class JSch{
*/
public static String getConfig(String key){
synchronized(config){
return (String)(config.get(key));
if(key.equals("PubkeyAcceptedKeyTypes")){
key="PubkeyAcceptedAlgorithms";
}
return config.get(key);
}
}
@@ -553,11 +646,12 @@ public class JSch{
*
* @param newconf configurations
*/
public static void setConfig(java.util.Hashtable newconf){
public static void setConfig(Hashtable<String, String> newconf){
synchronized(config){
for(java.util.Enumeration e=newconf.keys() ; e.hasMoreElements() ;) {
String key=(String)(e.nextElement());
config.put(key, (String)(newconf.get(key)));
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));
}
}
}
@@ -569,13 +663,19 @@ public class JSch{
* @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
* @param logger logger or <code>null</code> if no logging
* should take place
*
* @see com.jcraft.jsch.Logger
*/
@@ -584,7 +684,33 @@ public class JSch{
JSch.logger=logger;
}
static Logger getLogger(){
/**
* 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() {
if (this.instLogger == null) {
return logger;
}
return instLogger;
}
/**
* 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) {
this.instLogger = 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;
}
}

View File

@@ -0,0 +1,69 @@
package com.jcraft.jsch;
/**
* 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(
"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 "";
}
}
}

View File

@@ -30,7 +30,7 @@ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package com.jcraft.jsch;
class JSchAuthCancelException extends JSchException{
//private static final long serialVersionUID=3204965907117900987L;
private static final long serialVersionUID=-1L;
String method;
JSchAuthCancelException () {
super();

View File

@@ -30,8 +30,7 @@ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package com.jcraft.jsch;
public class JSchException extends Exception{
//private static final long serialVersionUID=-1319309923966731989L;
private Throwable cause=null;
private static final long serialVersionUID=-1L;
public JSchException () {
super();
}
@@ -39,10 +38,6 @@ public class JSchException extends Exception{
super(s);
}
public JSchException (String s, Throwable e) {
super(s);
this.cause=e;
}
public Throwable getCause(){
return this.cause;
super(s, e);
}
}

View File

@@ -30,7 +30,7 @@ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package com.jcraft.jsch;
class JSchPartialAuthException extends JSchException{
//private static final long serialVersionUID=-378849862323360367L;
private static final long serialVersionUID=-1L;
String methods;
public JSchPartialAuthException () {
super();

View File

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

View File

@@ -0,0 +1,53 @@
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 stlogger = Logger.getLogger(JSch.class.getName());
private final Logger logger;
public JulLogger() {
this(stlogger);
}
JulLogger(Logger logger) {
this.logger = logger;
}
@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;
}
}
}

View File

@@ -69,6 +69,11 @@ public abstract class KeyExchange{
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();
@@ -76,12 +81,14 @@ public abstract class KeyExchange{
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";
}
@@ -89,18 +96,18 @@ public abstract class KeyExchange{
return key_alg_name;
}
protected static String[] guess(byte[]I_S, byte[]I_C){
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(JSch.getLogger().isEnabled(Logger.INFO)){
if(session.getLogger().isEnabled(Logger.INFO)){
for(int i=0; i<PROPOSAL_MAX; i++){
JSch.getLogger().log(Logger.INFO,
session.getLogger().log(Logger.INFO,
"kex: server: "+Util.byte2str(sb.getString()));
}
for(int i=0; i<PROPOSAL_MAX; i++){
JSch.getLogger().log(Logger.INFO,
session.getLogger().log(Logger.INFO,
"kex: client: "+Util.byte2str(cb.getString()));
}
sb.setOffSet(17);
@@ -116,13 +123,13 @@ public abstract class KeyExchange{
loop:
while(j<cp.length){
while(j<cp.length && cp[j]!=',')j++;
if(k==j) return null;
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) return null;
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;
@@ -137,21 +144,46 @@ public abstract class KeyExchange{
guess[i]="";
}
else if(guess[i]==null){
return null;
throw new JSchAlgoNegoFailException(i, Util.byte2str(cp), Util.byte2str(sp));
}
}
if(JSch.getLogger().isEnabled(Logger.INFO)){
JSch.getLogger().log(Logger.INFO,
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"+
" "+guess[PROPOSAL_ENC_ALGS_STOC]+
" "+guess[PROPOSAL_MAC_ALGS_STOC]+
" "+guess[PROPOSAL_COMP_ALGS_STOC]);
JSch.getLogger().log(Logger.INFO,
" 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"+
" "+guess[PROPOSAL_ENC_ALGS_CTOS]+
" "+guess[PROPOSAL_MAC_ALGS_CTOS]+
" "+guess[PROPOSAL_COMP_ALGS_CTOS]);
" cipher: "+guess[PROPOSAL_ENC_ALGS_CTOS]+
" MAC: "+(_c2sAEAD?("<implicit>"):(guess[PROPOSAL_MAC_ALGS_CTOS]))+
" compression: "+guess[PROPOSAL_COMP_ALGS_CTOS]);
}
return guess;
@@ -160,11 +192,12 @@ public abstract class KeyExchange{
public String getFingerPrint(){
HASH hash=null;
try{
Class c=Class.forName(session.getConfig("md5"));
hash=(HASH)(c.newInstance());
String _c=session.getConfig("FingerprintHash").toLowerCase();
Class<? extends HASH> c=Class.forName(session.getConfig(_c)).asSubclass(HASH.class);
hash=c.getDeclaredConstructor().newInstance();
}
catch(Exception e){ System.err.println("getFingerPrint: "+e); }
return Util.getFingerPrint(hash, getHostKey());
return Util.getFingerPrint(hash, getHostKey(), true, false);
}
byte[] getK(){ return K; }
byte[] getH(){ return H; }
@@ -213,9 +246,11 @@ public abstract class KeyExchange{
n=tmp;
SignatureRSA sig=null;
Buffer buf=new Buffer(sig_of_H);
String foo=Util.byte2str(buf.getString());
try{
Class c=Class.forName(session.getConfig("signature.rsa"));
sig=(SignatureRSA)(c.newInstance());
Class<? extends SignatureRSA> c=Class.forName(session.getConfig(foo)).asSubclass(SignatureRSA.class);
sig=c.getDeclaredConstructor().newInstance();
sig.init();
}
catch(Exception e){
@@ -225,9 +260,9 @@ public abstract class KeyExchange{
sig.update(H);
result=sig.verify(sig_of_H);
if(JSch.getLogger().isEnabled(Logger.INFO)){
JSch.getLogger().log(Logger.INFO,
"ssh_rsa_verify: signature "+result);
if(session.getLogger().isEnabled(Logger.INFO)){
session.getLogger().log(Logger.INFO,
"ssh_rsa_verify: "+foo+" signature "+result);
}
}
else if(alg.equals("ssh-dss")){
@@ -259,8 +294,8 @@ public abstract class KeyExchange{
SignatureDSA sig=null;
try{
Class c=Class.forName(session.getConfig("signature.dss"));
sig=(SignatureDSA)(c.newInstance());
Class<? extends SignatureDSA> c=Class.forName(session.getConfig("signature.dss")).asSubclass(SignatureDSA.class);
sig=c.getDeclaredConstructor().newInstance();
sig.init();
}
catch(Exception e){
@@ -270,8 +305,8 @@ public abstract class KeyExchange{
sig.update(H);
result=sig.verify(sig_of_H);
if(JSch.getLogger().isEnabled(Logger.INFO)){
JSch.getLogger().log(Logger.INFO,
if(session.getLogger().isEnabled(Logger.INFO)){
session.getLogger().log(Logger.INFO,
"ssh_dss_verify: signature "+result);
}
}
@@ -301,8 +336,8 @@ public abstract class KeyExchange{
SignatureECDSA sig=null;
try{
Class c=Class.forName(session.getConfig(alg));
sig=(SignatureECDSA)(c.newInstance());
Class<? extends SignatureECDSA> c=Class.forName(session.getConfig(alg)).asSubclass(SignatureECDSA.class);
sig=c.getDeclaredConstructor().newInstance();
sig.init();
}
catch(Exception e){
@@ -314,6 +349,44 @@ public abstract class KeyExchange{
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){
System.err.println(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{
System.err.println("unknown alg");

View File

@@ -29,25 +29,31 @@ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package com.jcraft.jsch;
import java.io.FileOutputStream;
import java.io.FileInputStream;
import java.io.File;
import java.io.IOException;
import java.io.*;
import java.util.Arrays;
import java.util.Hashtable;
import java.util.Vector;
public abstract class KeyPair{
public static final int DEFERRED = -1;
public static final int ERROR=0;
public static final int DSA=1;
public static final int RSA=2;
public static final int ECDSA=3;
public static final int UNKNOWN=4;
public static final int ED25519=5;
public static final int ED448=6;
static final int VENDOR_OPENSSH=0;
static final int VENDOR_FSECURE=1;
static final int VENDOR_PUTTY=2;
static final int VENDOR_PKCS8=3;
static final int VENDOR_OPENSSH_V1 = 4;
int vendor=VENDOR_OPENSSH;
private static final byte[] AUTH_MAGIC = Util.str2byte("openssh-key-v1\0");
private static final byte[] cr=Util.str2byte("\n");
public static KeyPair genKeyPair(JSch jsch, int type) throws JSchException{
@@ -58,6 +64,8 @@ public abstract class KeyPair{
if(type==DSA){ kpair=new KeyPairDSA(jsch); }
else if(type==RSA){ kpair=new KeyPairRSA(jsch); }
else if(type==ECDSA){ kpair=new KeyPairECDSA(jsch); }
else if(type==ED25519){ kpair=new KeyPairEd25519(jsch); }
else if(type==ED448){ kpair=new KeyPairEd448(jsch); }
if(kpair!=null){
kpair.generate(key_size);
}
@@ -68,10 +76,12 @@ public abstract class KeyPair{
abstract byte[] getBegin();
abstract byte[] getEnd();
abstract int getKeySize();
public abstract int getKeySize();
public abstract byte[] getSignature(byte[] data);
public abstract byte[] getSignature(byte[] data, String alg);
public abstract Signature getVerifier();
public abstract Signature getVerifier(String alg);
public abstract byte[] forSSHAgent() throws JSchException;
@@ -86,12 +96,15 @@ public abstract class KeyPair{
protected String publicKeyComment = "no comment";
JSch jsch=null;
private Cipher cipher;
protected Cipher cipher;
private HASH hash;
private Random random;
private byte[] passphrase;
protected String kdfName;
protected byte[] kdfOptions;
public KeyPair(JSch jsch){
this.jsch=jsch;
}
@@ -104,9 +117,9 @@ public abstract class KeyPair{
/**
* Writes the plain private key to the given output stream.
* @param out output stream
* @see #writePrivateKey(java.io.OutputStream out, byte[] passphrase)
* @see #writePrivateKey(OutputStream out, byte[] passphrase)
*/
public void writePrivateKey(java.io.OutputStream out){
public void writePrivateKey(OutputStream out){
this.writePrivateKey(out, null);
}
@@ -115,7 +128,7 @@ public abstract class KeyPair{
* @param out output stream
* @param passphrase a passphrase to encrypt the private key
*/
public void writePrivateKey(java.io.OutputStream out, byte[] passphrase){
public void writePrivateKey(OutputStream out, byte[] passphrase){
if(passphrase == null)
passphrase = this.passphrase;
@@ -125,7 +138,7 @@ public abstract class KeyPair{
if(encoded!=plain)
Util.bzero(plain);
byte[] iv=_iv[0];
byte[] prv=Util.toBase64(encoded, 0, encoded.length);
byte[] prv=Util.toBase64(encoded, 0, encoded.length, true);
try{
out.write(getBegin()); out.write(cr);
@@ -179,9 +192,9 @@ public abstract class KeyPair{
* @param out output stream
* @param comment comment
*/
public void writePublicKey(java.io.OutputStream out, String comment){
public void writePublicKey(OutputStream out, String comment){
byte[] pubblob=getPublicKeyBlob();
byte[] pub=Util.toBase64(pubblob, 0, pubblob.length);
byte[] pub=Util.toBase64(pubblob, 0, pubblob.length, true);
try{
out.write(getKeyTypeName()); out.write(space);
out.write(pub, 0, pub.length); out.write(space);
@@ -196,9 +209,9 @@ public abstract class KeyPair{
* Writes the public key with the specified comment to the file.
* @param name file name
* @param comment comment
* @see #writePublicKey(java.io.OutputStream out, String comment)
* @see #writePublicKey(OutputStream out, String comment)
*/
public void writePublicKey(String name, String comment) throws java.io.FileNotFoundException, java.io.IOException{
public void writePublicKey(String name, String comment) throws FileNotFoundException, IOException{
FileOutputStream fos=new FileOutputStream(name);
writePublicKey(fos, comment);
fos.close();
@@ -210,9 +223,9 @@ public abstract class KeyPair{
* @param out output stream
* @param comment comment
*/
public void writeSECSHPublicKey(java.io.OutputStream out, String comment){
public void writeSECSHPublicKey(OutputStream out, String comment){
byte[] pubblob=getPublicKeyBlob();
byte[] pub=Util.toBase64(pubblob, 0, pubblob.length);
byte[] pub=Util.toBase64(pubblob, 0, pubblob.length, true);
try{
out.write(Util.str2byte("---- BEGIN SSH2 PUBLIC KEY ----")); out.write(cr);
out.write(Util.str2byte("Comment: \""+comment+"\"")); out.write(cr);
@@ -234,9 +247,9 @@ public abstract class KeyPair{
* the format defined in http://www.ietf.org/rfc/rfc4716.txt
* @param name file name
* @param comment comment
* @see #writeSECSHPublicKey(java.io.OutputStream out, String comment)
* @see #writeSECSHPublicKey(OutputStream out, String comment)
*/
public void writeSECSHPublicKey(String name, String comment) throws java.io.FileNotFoundException, java.io.IOException{
public void writeSECSHPublicKey(String name, String comment) throws FileNotFoundException, IOException{
FileOutputStream fos=new FileOutputStream(name);
writeSECSHPublicKey(fos, comment);
fos.close();
@@ -247,7 +260,7 @@ public abstract class KeyPair{
* @param name file name
* @see #writePrivateKey(String name, byte[] passphrase)
*/
public void writePrivateKey(String name) throws java.io.FileNotFoundException, java.io.IOException{
public void writePrivateKey(String name) throws FileNotFoundException, IOException{
this.writePrivateKey(name, null);
}
@@ -255,9 +268,9 @@ public abstract class KeyPair{
* Writes the cyphered private key to the file.
* @param name file name
* @param passphrase a passphrase to encrypt the private key
* @see #writePrivateKey(java.io.OutputStream out, byte[] passphrase)
* @see #writePrivateKey(OutputStream out, byte[] passphrase)
*/
public void writePrivateKey(String name, byte[] passphrase) throws java.io.FileNotFoundException, java.io.IOException{
public void writePrivateKey(String name, byte[] passphrase) throws FileNotFoundException, IOException{
FileOutputStream fos=new FileOutputStream(name);
writePrivateKey(fos, passphrase);
fos.close();
@@ -271,7 +284,7 @@ public abstract class KeyPair{
if(hash==null) hash=genHash();
byte[] kblob=getPublicKeyBlob();
if(kblob==null) return null;
return Util.getFingerPrint(hash, kblob);
return Util.getFingerPrint(hash, kblob, false, true);
}
private byte[] encrypt(byte[] plain, byte[][] _iv, byte[] passphrase){
@@ -386,8 +399,8 @@ public abstract class KeyPair{
private Random genRandom(){
if(random==null){
try{
Class c=Class.forName(jsch.getConfig("random"));
random=(Random)(c.newInstance());
Class<? extends Random> c=Class.forName(JSch.getConfig("random")).asSubclass(Random.class);
random=c.getDeclaredConstructor().newInstance();
}
catch(Exception e){ System.err.println("connect: random "+e); }
}
@@ -396,8 +409,8 @@ public abstract class KeyPair{
private HASH genHash(){
try{
Class c=Class.forName(jsch.getConfig("md5"));
hash=(HASH)(c.newInstance());
Class<? extends HASH> c=Class.forName(JSch.getConfig("md5")).asSubclass(HASH.class);
hash=c.getDeclaredConstructor().newInstance();
hash.init();
}
catch(Exception e){
@@ -406,9 +419,8 @@ public abstract class KeyPair{
}
private Cipher genCipher(){
try{
Class c;
c=Class.forName(jsch.getConfig("3des-cbc"));
cipher=(Cipher)(c.newInstance());
Class<? extends Cipher> c=Class.forName(JSch.getConfig("3des-cbc")).asSubclass(Cipher.class);
cipher=c.getDeclaredConstructor().newInstance();
}
catch(Exception e){
}
@@ -453,8 +465,8 @@ public abstract class KeyPair{
System.arraycopy(hn, 0, key, 0, key.length);
}
else if(vendor==VENDOR_PUTTY){
Class c=Class.forName((String)jsch.getConfig("sha-1"));
HASH sha1=(HASH)(c.newInstance());
Class<? extends HASH> c=Class.forName(JSch.getConfig("sha-1")).asSubclass(HASH.class);
HASH sha1=c.getDeclaredConstructor().newInstance();
tmp = new byte[4];
key = new byte[20*2];
for(int i = 0; i < 2; i++){
@@ -473,8 +485,9 @@ public abstract class KeyPair{
}
/**
* @deprecated use #writePrivateKey(java.io.OutputStream out, byte[] passphrase)
* @deprecated use #writePrivateKey(OutputStream out, byte[] passphrase)
*/
@Deprecated
public void setPassphrase(String passphrase){
if(passphrase==null || passphrase.length()==0){
setPassphrase((byte[])null);
@@ -487,6 +500,7 @@ public abstract class KeyPair{
/**
* @deprecated use #writePrivateKey(String name, byte[] passphrase)
*/
@Deprecated
public void setPassphrase(byte[] passphrase){
if(passphrase!=null && passphrase.length==0)
passphrase=null;
@@ -540,7 +554,7 @@ public abstract class KeyPair{
prvkey = Util.fromFile(prvfile);
}
catch(IOException e){
throw new JSchException(e.toString(), (Throwable)e);
throw new JSchException(e.toString(), e);
}
String _pubfile=pubfile;
@@ -553,7 +567,7 @@ public abstract class KeyPair{
}
catch(IOException e){
if(pubfile!=null){
throw new JSchException(e.toString(), (Throwable)e);
throw new JSchException(e.toString(), e);
}
}
@@ -577,17 +591,20 @@ public abstract class KeyPair{
int vendor=VENDOR_OPENSSH;
String publicKeyComment = "";
Cipher cipher=null;
String kdfName = null;
byte[] kdfOptions = null;
// prvkey from "ssh-add" command on the remote.
if(pubkey==null &&
prvkey!=null &&
(prvkey.length>11 &&
prvkey[0]==0 && prvkey[1]==0 && prvkey[2]==0 &&
(prvkey[3]==7 || prvkey[3]==19))){
// length of key type string
(prvkey[3]==7 || prvkey[3]==9 || prvkey[3]==11 || prvkey[3]==19))){
Buffer buf=new Buffer(prvkey);
buf.skip(prvkey.length); // for using Buffer#available()
String _type = new String(buf.getString()); // ssh-rsa or ssh-dss
String _type = Util.byte2str(buf.getString()); // ssh-rsa or ssh-dss
buf.rewind();
KeyPair kpair=null;
@@ -602,8 +619,14 @@ public abstract class KeyPair{
_type.equals("ecdsa-sha2-nistp521")){
kpair=KeyPairECDSA.fromSSHAgent(jsch, buf);
}
else if(_type.equals("ssh-ed25519")){
kpair=KeyPairEd25519.fromSSHAgent(jsch, buf);
}
else if(_type.equals("ssh-ed448")){
kpair=KeyPairEd448.fromSSHAgent(jsch, buf);
}
else{
throw new JSchException("privatekey: invalid key "+new String(prvkey, 4, 7));
throw new JSchException("privatekey: invalid key "+Util.byte2str(prvkey, 4, 7));
}
return kpair;
}
@@ -634,7 +657,7 @@ public abstract class KeyPair{
if(buf[i]=='B'&& i+3<len && buf[i+1]=='E'&& buf[i+2]=='G'&& buf[i+3]=='I'){
i+=6;
if(i+2 >= len)
throw new JSchException("invalid privatekey: "+prvkey);
throw new JSchException("invalid privatekey");
if(buf[i]=='D'&& buf[i+1]=='S'&& buf[i+2]=='A'){ type=DSA; }
else if(buf[i]=='R'&& buf[i+1]=='S'&& buf[i+2]=='A'){ type=RSA; }
else if(buf[i]=='E'&& buf[i+1]=='C'){ type=ECDSA; }
@@ -659,9 +682,12 @@ public abstract class KeyPair{
type=UNKNOWN;
vendor=VENDOR_PKCS8;
i+=5;
}
else{
throw new JSchException("invalid privatekey: "+prvkey);
} else if (isOpenSSHPrivateKey(buf, i, len)) {
type = UNKNOWN;
vendor = VENDOR_OPENSSH_V1;
} else {
throw new JSchException("invalid privatekey");
}
i+=3;
continue;
@@ -669,42 +695,42 @@ public abstract class KeyPair{
if(buf[i]=='A'&& i+7<len && buf[i+1]=='E'&& buf[i+2]=='S'&& buf[i+3]=='-' &&
buf[i+4]=='2'&& buf[i+5]=='5'&& buf[i+6]=='6'&& buf[i+7]=='-'){
i+=8;
if(Session.checkCipher((String)jsch.getConfig("aes256-cbc"))){
Class c=Class.forName((String)jsch.getConfig("aes256-cbc"));
cipher=(Cipher)(c.newInstance());
if(Session.checkCipher(JSch.getConfig("aes256-cbc"))){
Class<? extends Cipher> c=Class.forName(JSch.getConfig("aes256-cbc")).asSubclass(Cipher.class);
cipher=c.getDeclaredConstructor().newInstance();
// key=new byte[cipher.getBlockSize()];
iv=new byte[cipher.getIVSize()];
}
else{
throw new JSchException("privatekey: aes256-cbc is not available "+prvkey);
throw new JSchException("privatekey: aes256-cbc is not available");
}
continue;
}
if(buf[i]=='A'&& i+7<len && buf[i+1]=='E'&& buf[i+2]=='S'&& buf[i+3]=='-' &&
buf[i+4]=='1'&& buf[i+5]=='9'&& buf[i+6]=='2'&& buf[i+7]=='-'){
i+=8;
if(Session.checkCipher((String)jsch.getConfig("aes192-cbc"))){
Class c=Class.forName((String)jsch.getConfig("aes192-cbc"));
cipher=(Cipher)(c.newInstance());
if(Session.checkCipher(JSch.getConfig("aes192-cbc"))){
Class<? extends Cipher> c=Class.forName(JSch.getConfig("aes192-cbc")).asSubclass(Cipher.class);
cipher=c.getDeclaredConstructor().newInstance();
// key=new byte[cipher.getBlockSize()];
iv=new byte[cipher.getIVSize()];
}
else{
throw new JSchException("privatekey: aes192-cbc is not available "+prvkey);
throw new JSchException("privatekey: aes192-cbc is not available");
}
continue;
}
if(buf[i]=='A'&& i+7<len && buf[i+1]=='E'&& buf[i+2]=='S'&& buf[i+3]=='-' &&
buf[i+4]=='1'&& buf[i+5]=='2'&& buf[i+6]=='8'&& buf[i+7]=='-'){
i+=8;
if(Session.checkCipher((String)jsch.getConfig("aes128-cbc"))){
Class c=Class.forName((String)jsch.getConfig("aes128-cbc"));
cipher=(Cipher)(c.newInstance());
if(Session.checkCipher(JSch.getConfig("aes128-cbc"))){
Class<? extends Cipher> c=Class.forName(JSch.getConfig("aes128-cbc")).asSubclass(Cipher.class);
cipher=c.getDeclaredConstructor().newInstance();
// key=new byte[cipher.getBlockSize()];
iv=new byte[cipher.getIVSize()];
}
else{
throw new JSchException("privatekey: aes128-cbc is not available "+prvkey);
throw new JSchException("privatekey: aes128-cbc is not available");
}
continue;
}
@@ -744,7 +770,7 @@ public abstract class KeyPair{
if(buf!=null){
if(type==ERROR){
throw new JSchException("invalid privatekey: "+prvkey);
throw new JSchException("invalid privatekey");
}
int start = i;
@@ -754,7 +780,7 @@ public abstract class KeyPair{
}
if((len-i) == 0 || (i-start) == 0){
throw new JSchException("invalid privatekey: "+prvkey);
throw new JSchException("invalid privatekey");
}
// The content of 'buf' will be changed, so it should be copied.
@@ -796,7 +822,7 @@ public abstract class KeyPair{
_buf.getInt(); // 0x3f6ff9be
_buf.getInt();
byte[]_type=_buf.getString();
//System.err.println("type: "+new String(_type));
//System.err.println("type: "+Util.byte2str(_type));
String _cipher=Util.byte2str(_buf.getString());
//System.err.println("cipher: "+_cipher);
if(_cipher.equals("3des-cbc")){
@@ -805,7 +831,7 @@ public abstract class KeyPair{
_buf.getByte(foo);
data=foo;
encrypted=true;
throw new JSchException("unknown privatekey format: "+prvkey);
throw new JSchException("unknown privatekey format");
}
else if(_cipher.equals("none")){
_buf.getInt();
@@ -818,6 +844,41 @@ public abstract class KeyPair{
data=foo;
}
}
// OPENSSH V1 PRIVATE KEY
else if (data != null &&
Util.array_equals(AUTH_MAGIC, Arrays.copyOfRange(data, 0, AUTH_MAGIC.length))) {
vendor = VENDOR_OPENSSH_V1;
Buffer buffer = new Buffer(data);
byte[] magic = new byte[AUTH_MAGIC.length];
buffer.getByte(magic);
String cipherName = Util.byte2str(buffer.getString());
kdfName = Util.byte2str(buffer.getString()); // string kdfname
kdfOptions = buffer.getString(); // string kdfoptions
int nrKeys = buffer.getInt(); // int number of keys N; Should be 1
if (nrKeys != 1) {
throw new IOException("We don't support having more than 1 key in the file (yet).");
}
pubkey = buffer.getString();
if ("none".equals(cipherName)) {
encrypted = false;
data = buffer.getString();
type = readOpenSSHKeyv1(data);
} else if (Session.checkCipher(JSch.getConfig(cipherName))) {
encrypted = true;
Class<? extends Cipher> c = Class.forName(JSch.getConfig(cipherName)).asSubclass(Cipher.class);
cipher = c.getDeclaredConstructor().newInstance();
data = buffer.getString();
// the type can only be determined after encryption, so we take this intermediate here:
type = DEFERRED;
} else {
throw new JSchException("cipher " + cipherName + " is not available");
}
}
if(pubkey!=null){
try{
@@ -871,6 +932,8 @@ public abstract class KeyPair{
buf.length>7){
if(buf[4]=='d'){ type=DSA; }
else if(buf[4]=='r'){ type=RSA; }
else if(buf[4]=='e' && buf[6]=='2'){ type=ED25519; }
else if(buf[4]=='e' && buf[6]=='4'){ type=ED448; }
}
i=0;
while(i<len){ if(buf[i]==' ')break; i++;} i++;
@@ -884,7 +947,7 @@ public abstract class KeyPair{
while(i<len){ if(buf[i]=='\n')break; i++;}
if(i>0 && buf[i-1]==0x0d) i--;
if(start<i){
publicKeyComment = new String(buf, start, i-start);
publicKeyComment = Util.byte2str(buf, start, i-start);
}
}
}
@@ -904,7 +967,7 @@ public abstract class KeyPair{
while(i<len){ if(buf[i]=='\n')break; i++;}
if(i>0 && buf[i-1]==0x0d) i--;
if(start<i){
publicKeyComment = new String(buf, start, i-start);
publicKeyComment = Util.byte2str(buf, start, i-start);
}
}
}
@@ -916,16 +979,21 @@ public abstract class KeyPair{
}
catch(Exception e){
if(e instanceof JSchException) throw (JSchException)e;
if(e instanceof Throwable)
throw new JSchException(e.toString(), (Throwable)e);
throw new JSchException(e.toString());
throw new JSchException(e.toString(), e);
}
return getKeyPair(jsch, prvkey, pubkey, iv, encrypted, data, publickeyblob, type, vendor, publicKeyComment, cipher, kdfName, kdfOptions);
}
static KeyPair getKeyPair(JSch jsch, byte[] prvkey, byte[] pubkey, byte[] iv, boolean encrypted, byte[] data, byte[] publickeyblob, int type, int vendor, String publicKeyComment, Cipher cipher, String kdfName, byte[] kdfOptions) throws JSchException {
KeyPair kpair=null;
if(type==DSA){ kpair=new KeyPairDSA(jsch); }
else if(type==RSA){ kpair=new KeyPairRSA(jsch); }
else if(type==ECDSA){ kpair=new KeyPairECDSA(jsch, pubkey); }
else if(type==ED25519){ kpair=new KeyPairEd25519(jsch, pubkey, prvkey); }
else if(type==ED448){ kpair=new KeyPairEd448(jsch, pubkey, prvkey); }
else if(vendor==VENDOR_PKCS8){ kpair = new KeyPairPKCS8(jsch); }
else if (type == DEFERRED) { kpair = new KeyPairDeferred(jsch); }
if(kpair!=null){
kpair.encrypted=encrypted;
@@ -933,6 +1001,8 @@ public abstract class KeyPair{
kpair.vendor=vendor;
kpair.publicKeyComment=publicKeyComment;
kpair.cipher=cipher;
kpair.kdfName = kdfName;
kpair.kdfOptions = kdfOptions;
if(encrypted){
kpair.encrypted=true;
@@ -945,7 +1015,7 @@ public abstract class KeyPair{
return kpair;
}
else{
throw new JSchException("invalid privatekey: "+prvkey);
throw new JSchException("invalid privatekey");
}
}
}
@@ -953,6 +1023,49 @@ public abstract class KeyPair{
return kpair;
}
/**
* reads openssh key v1 format and returns key type.
*
* @param data
* @return key type 1=DSA, 2=RSA, 3=ECDSA, 4=UNKNOWN, 5=ED25519, 6=ED448
* @throws IOException
* @throws JSchException
*/
static int readOpenSSHKeyv1(byte[] data) throws IOException, JSchException {
if (data.length % 8 != 0) {
throw new IOException("The private key section must be a multiple of the block size (8)");
}
final Buffer prvKEyBuffer = new Buffer(data);
int checkInt1 = prvKEyBuffer.getInt(); // uint32 checkint1
int checkInt2 = prvKEyBuffer.getInt(); // uint32 checkint2
if (checkInt1 != checkInt2) {
throw new JSchException("openssh v1 key check failed. Wrong passphrase?");
}
// The private key section contains both the public key and the private key
String keyType = Util.byte2str(prvKEyBuffer.getString()); // string keytype
if (keyType.equalsIgnoreCase("ssh-rsa")) {
return RSA;
} else if (keyType.startsWith("ssh-dss")) {
return DSA;
} else if (keyType.startsWith("ecdsa-sha2")) {
return ECDSA;
} else if (keyType.startsWith("ssh-ed25519")) {
return ED25519;
} else if (keyType.startsWith("ssh-ed448")) {
return ED448;
} else throw new JSchException("keytype " + keyType + " not supported as part of openssh v1 format");
}
private static boolean isOpenSSHPrivateKey(byte[] buf, int i, int len) {
String ident = "OPENSSH PRIVATE KEY-----";
return i + ident.length() < len && ident.equals(Util.byte2str(Arrays.copyOfRange(buf, i, i + ident.length())));
}
static private byte a2b(byte c){
if('0'<=c&&c<='9') return (byte)(c-'0');
return (byte)(c-'a'+10);
@@ -966,6 +1079,8 @@ public abstract class KeyPair{
Util.bzero(passphrase);
}
@SuppressWarnings("deprecation")
@Override
public void finalize(){
dispose();
}
@@ -991,19 +1106,19 @@ public abstract class KeyPair{
int lines = 0;
Buffer buffer = new Buffer(buf);
java.util.Hashtable v = new java.util.Hashtable();
Hashtable<String, String> v = new Hashtable<>();
while(true){
if(!parseHeader(buffer, v))
break;
}
String typ = (String)v.get("PuTTY-User-Key-File-2");
String typ = v.get("PuTTY-User-Key-File-2");
if(typ == null){
return null;
}
lines = Integer.parseInt((String)v.get("Public-Lines"));
lines = Integer.parseInt(v.get("Public-Lines"));
pubkey = parseLines(buffer, lines);
while(true){
@@ -1011,7 +1126,7 @@ public abstract class KeyPair{
break;
}
lines = Integer.parseInt((String)v.get("Private-Lines"));
lines = Integer.parseInt(v.get("Private-Lines"));
prvkey = parseLines(buffer, lines);
while(true){
@@ -1065,12 +1180,12 @@ public abstract class KeyPair{
kpair.encrypted = !v.get("Encryption").equals("none");
kpair.vendor = VENDOR_PUTTY;
kpair.publicKeyComment = (String)v.get("Comment");
kpair.publicKeyComment = v.get("Comment");
if(kpair.encrypted){
if(Session.checkCipher((String)jsch.getConfig("aes256-cbc"))){
if(Session.checkCipher(JSch.getConfig("aes256-cbc"))){
try {
Class c=Class.forName((String)jsch.getConfig("aes256-cbc"));
kpair.cipher=(Cipher)(c.newInstance());
Class<? extends Cipher> c=Class.forName(JSch.getConfig("aes256-cbc")).asSubclass(Cipher.class);
kpair.cipher=c.getDeclaredConstructor().newInstance();
kpair.iv=new byte[kpair.cipher.getIVSize()];
}
catch(Exception e){
@@ -1123,7 +1238,7 @@ public abstract class KeyPair{
return data;
}
private static boolean parseHeader(Buffer buffer, java.util.Hashtable v){
private static boolean parseHeader(Buffer buffer, Hashtable<String, String> v){
byte[] buf = buffer.buffer;
int index = buffer.index;
String key = null;
@@ -1133,7 +1248,7 @@ public abstract class KeyPair{
break;
}
if(buf[i] == ':'){
key = new String(buf, index, i - index);
key = Util.byte2str(buf, index, i - index);
i++;
if(i < buf.length && buf[i] == ' '){
i++;
@@ -1148,7 +1263,7 @@ public abstract class KeyPair{
for(int i = index; i < buf.length; i++){
if(buf[i] == 0x0d){
value = new String(buf, index, i - index);
value = Util.byte2str(buf, index, i - index);
i++;
if(i < buf.length && buf[i] == 0x0a){
i++;
@@ -1173,7 +1288,8 @@ public abstract class KeyPair{
this.cipher=kpair.cipher;
}
class ASN1Exception extends Exception {
static class ASN1Exception extends Exception {
private static final long serialVersionUID=-1L;
}
class ASN1 {
@@ -1233,7 +1349,7 @@ public abstract class KeyPair{
return new ASN1[0];
}
int index=indexp[0];
java.util.Vector values = new java.util.Vector();
Vector<ASN1> values = new Vector<>();
while(length>0) {
index++; length--;
int tmp=index;
@@ -1247,7 +1363,7 @@ public abstract class KeyPair{
}
ASN1[] result = new ASN1[values.size()];
for(int i = 0; i <values.size(); i++) {
result[i]=(ASN1)values.elementAt(i);
result[i]=values.elementAt(i);
}
return result;
}

View File

@@ -29,7 +29,9 @@ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package com.jcraft.jsch;
public class KeyPairDSA extends KeyPair{
import java.math.BigInteger;
class KeyPairDSA extends KeyPair{
private byte[] P_array;
private byte[] Q_array;
private byte[] G_array;
@@ -39,11 +41,11 @@ public class KeyPairDSA extends KeyPair{
//private int key_size=0;
private int key_size=1024;
public KeyPairDSA(JSch jsch){
KeyPairDSA(JSch jsch){
this(jsch, null, null, null, null, null);
}
public KeyPairDSA(JSch jsch,
KeyPairDSA(JSch jsch,
byte[] P_array,
byte[] Q_array,
byte[] G_array,
@@ -56,14 +58,15 @@ public class KeyPairDSA extends KeyPair{
this.pub_array = pub_array;
this.prv_array = prv_array;
if(P_array!=null)
key_size = (new java.math.BigInteger(P_array)).bitLength();
key_size = (new BigInteger(P_array)).bitLength();
}
@Override
void generate(int key_size) throws JSchException{
this.key_size=key_size;
try{
Class c=Class.forName(jsch.getConfig("keypairgen.dsa"));
KeyPairGenDSA keypairgen=(KeyPairGenDSA)(c.newInstance());
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();
@@ -75,18 +78,19 @@ public class KeyPairDSA extends KeyPair{
}
catch(Exception e){
//System.err.println("KeyPairDSA: "+e);
if(e instanceof Throwable)
throw new JSchException(e.toString(), (Throwable)e);
throw new JSchException(e.toString());
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
@@ -111,6 +115,7 @@ public class KeyPairDSA extends KeyPair{
return plain;
}
@Override
boolean parse(byte[] plain){
try{
@@ -124,7 +129,7 @@ public class KeyPairDSA extends KeyPair{
pub_array=buf.getMPIntBits();
prv_array=buf.getMPIntBits();
if(P_array!=null)
key_size = (new java.math.BigInteger(P_array)).bitLength();
key_size = (new BigInteger(P_array)).bitLength();
return true;
}
return false;
@@ -144,6 +149,29 @@ public class KeyPairDSA extends KeyPair{
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;
@@ -215,7 +243,7 @@ public class KeyPairDSA extends KeyPair{
index+=length;
if(P_array!=null)
key_size = (new java.math.BigInteger(P_array)).bitLength();
key_size = (new BigInteger(P_array)).bitLength();
}
catch(Exception e){
//System.err.println(e);
@@ -225,6 +253,7 @@ public class KeyPairDSA extends KeyPair{
return true;
}
@Override
public byte[] getPublicKeyBlob(){
byte[] foo=super.getPublicKeyBlob();
if(foo!=null) return foo;
@@ -240,17 +269,21 @@ public class KeyPairDSA extends KeyPair{
}
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 c=Class.forName((String)jsch.getConfig("signature.dss"));
SignatureDSA dsa=(SignatureDSA)(c.newInstance());
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);
@@ -267,10 +300,16 @@ public class KeyPairDSA extends KeyPair{
return null;
}
@Override
public byte[] getSignature(byte[] data, String alg){
return getSignature(data);
}
@Override
public Signature getVerifier(){
try{
Class c=Class.forName((String)jsch.getConfig("signature.dss"));
SignatureDSA dsa=(SignatureDSA)(c.newInstance());
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){
@@ -291,6 +330,11 @@ public class KeyPairDSA extends KeyPair{
return null;
}
@Override
public Signature getVerifier(String alg){
return getVerifier();
}
static KeyPair fromSSHAgent(JSch jsch, Buffer buf) throws JSchException {
byte[][] tmp = buf.getBytes(7, "invalid key format");
@@ -303,11 +347,12 @@ public class KeyPairDSA extends KeyPair{
KeyPairDSA kpair = new KeyPairDSA(jsch,
P_array, Q_array, G_array,
pub_array, prv_array);
kpair.publicKeyComment = new String(tmp[6]);
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.");
@@ -325,6 +370,7 @@ public class KeyPairDSA extends KeyPair{
return result;
}
@Override
public void dispose(){
super.dispose();
Util.bzero(prv_array);

View File

@@ -0,0 +1,163 @@
package com.jcraft.jsch;
import com.jcraft.jsch.jbcrypt.BCrypt;
import java.util.Arrays;
/**
* A {@link KeyPair} which can only reveal its type and content after it was decrypted using {@link com.jcraft.jsch.KeyPairDeferred#decrypt(byte[])}.
* This is needed for openssh-v1-private-key format.
*/
class KeyPairDeferred extends KeyPair {
private KeyPair delegate;
KeyPairDeferred(JSch jsch) {
super(jsch);
}
@Override
public boolean decrypt(String _passphrase) {
return decrypt(Util.str2byte(_passphrase));
}
@Override
public boolean decrypt(byte[] _passphrase) {
try {
if (!isEncrypted()) {
return true;
}
if (_passphrase == null) {
jsch.getInstanceLogger().log(Logger.ERROR, "no passphrase set.");
return false;
}
initCipher(_passphrase);
byte[] plain = new byte[data.length];
cipher.update(data, 0, data.length, plain, 0);
// now we have decrypted key and can determine type
int type = readOpenSSHKeyv1(plain);
delegate = getKeyPair(jsch, null, null, null, false, plain, getPublicKeyBlob(), type, VENDOR_OPENSSH_V1, publicKeyComment, cipher, null, null);
return delegate != null;
} catch (Exception e) {
throw new IllegalArgumentException("Could not sucessfully decrypt openssh v1 key", e);
}
}
private void initCipher(byte[] _passphrase) throws Exception {
// the encrypted private key is here:
if ("bcrypt".equals(kdfName)) {
Buffer opts = new Buffer(kdfOptions);
byte[] keyiv = new byte[48];
new BCrypt().pbkdf(_passphrase, opts.getString(), opts.getInt(), keyiv);
Arrays.fill(_passphrase, (byte) 0);
byte[] key = Arrays.copyOfRange(keyiv, 0, 32);
byte[] iv = Arrays.copyOfRange(keyiv, 32, 48);
cipher.init(Cipher.DECRYPT_MODE, key, iv);
} else {
throw new IllegalStateException("No support for KDF '" + kdfName + "'.");
}
}
@Override
void generate(int key_size) throws JSchException {
throw new UnsupportedOperationException();
}
@Override
byte[] getBegin() {
return requireDecrypted(delegate).getBegin();
}
@Override
byte[] getEnd() {
return requireDecrypted(delegate).getEnd();
}
@Override
public int getKeySize() {
return requireDecrypted(delegate).getKeySize();
}
@Override
public byte[] getSignature(byte[] data) {
return requireDecrypted(delegate).getSignature(data);
}
@Override
public byte[] getSignature(byte[] data, String alg) {
return requireDecrypted(delegate).getSignature(data, alg);
}
@Override
public Signature getVerifier() {
return requireDecrypted(delegate).getVerifier();
}
@Override
public Signature getVerifier(String alg) {
return requireDecrypted(delegate).getVerifier(alg);
}
@Override
public byte[] forSSHAgent() throws JSchException {
return requireDecrypted(delegate).forSSHAgent();
}
@Override
byte[] getPrivateKey() {
return requireDecrypted(delegate).getPrivateKey();
}
@Override
byte[] getKeyTypeName() {
return requireDecrypted(delegate).getKeyTypeName();
}
@Override
public int getKeyType() {
return requireDecrypted(delegate).getKeyType();
}
@Override
boolean parse(byte[] data) {
return requireDecrypted(delegate).parse(data);
}
@Override
public byte[] getPublicKeyBlob() {
return delegate != null ? delegate.getPublicKeyBlob() : null;
}
@Override
public String getPublicKeyComment() {
return requireDecrypted(delegate).getPublicKeyComment();
}
@Override
public String getFingerPrint() {
return requireDecrypted(delegate).getFingerPrint();
}
@Override
public boolean isEncrypted() {
return delegate != null ? delegate.isEncrypted() : super.isEncrypted();
}
private <T> T requireDecrypted(T obj) {
if (obj == null)
throw new IllegalStateException("encrypted key has not been decrypted yet.");
return obj;
}
}

View File

@@ -29,7 +29,9 @@ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package com.jcraft.jsch;
public class KeyPairECDSA extends KeyPair{
import java.util.Arrays;
class KeyPairECDSA extends KeyPair{
private static byte[][] oids = {
{(byte)0x06, (byte)0x08, (byte)0x2a, (byte)0x86, (byte)0x48, // 256
@@ -51,11 +53,11 @@ public class KeyPairECDSA extends KeyPair{
private int key_size=256;
public KeyPairECDSA(JSch jsch){
KeyPairECDSA(JSch jsch){
this(jsch, null, null, null, null);
}
public KeyPairECDSA(JSch jsch , byte[] pubkey){
KeyPairECDSA(JSch jsch , byte[] pubkey){
this(jsch, null, null, null, null);
if(pubkey!=null){
@@ -72,7 +74,7 @@ public class KeyPairECDSA extends KeyPair{
}
}
public KeyPairECDSA(JSch jsch,
KeyPairECDSA(JSch jsch,
byte[] name,
byte[] r_array,
byte[] s_array,
@@ -88,11 +90,12 @@ public class KeyPairECDSA extends KeyPair{
(prv_array.length>=48 ? 384 : 256);
}
@Override
void generate(int key_size) throws JSchException{
this.key_size=key_size;
try{
Class c=Class.forName(jsch.getConfig("keypairgen.ecdsa"));
KeyPairGenECDSA keypairgen=(KeyPairGenECDSA)(c.newInstance());
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();
@@ -102,9 +105,7 @@ public class KeyPairECDSA extends KeyPair{
keypairgen=null;
}
catch(Exception e){
if(e instanceof Throwable)
throw new JSchException(e.toString(), (Throwable)e);
throw new JSchException(e.toString());
throw new JSchException(e.toString(), e);
}
}
@@ -113,9 +114,12 @@ public class KeyPairECDSA extends KeyPair{
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;
@@ -160,6 +164,7 @@ public class KeyPairECDSA extends KeyPair{
return plain;
}
@Override
boolean parse(byte[] plain){
try{
@@ -190,6 +195,42 @@ public class KeyPairECDSA extends KeyPair{
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
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;
@@ -271,6 +312,7 @@ public class KeyPairECDSA extends KeyPair{
return true;
}
@Override
public byte[] getPublicKeyBlob(){
byte[] foo = super.getPublicKeyBlob();
@@ -279,7 +321,7 @@ public class KeyPairECDSA extends KeyPair{
if(r_array==null) return null;
byte[][] tmp = new byte[3][];
tmp[0] = Util.str2byte("ecdsa-sha2-"+new String(name));
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
@@ -289,20 +331,24 @@ public class KeyPairECDSA extends KeyPair{
return Buffer.fromBytes(tmp).buffer;
}
@Override
byte[] getKeyTypeName(){
return Util.str2byte("ecdsa-sha2-"+new String(name));
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 c=Class.forName((String)jsch.getConfig("ecdsa-sha2-"+new String(name)));
SignatureECDSA ecdsa=(SignatureECDSA)(c.newInstance());
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);
@@ -310,7 +356,7 @@ public class KeyPairECDSA extends KeyPair{
byte[] sig = ecdsa.sign();
byte[][] tmp = new byte[2][];
tmp[0] = Util.str2byte("ecdsa-sha2-"+new String(name));
tmp[0] = Util.str2byte("ecdsa-sha2-"+Util.byte2str(name));
tmp[1] = sig;
return Buffer.fromBytes(tmp).buffer;
}
@@ -320,10 +366,16 @@ public class KeyPairECDSA extends KeyPair{
return null;
}
@Override
public byte[] getSignature(byte[] data, String al){
return getSignature(data);
}
@Override
public Signature getVerifier(){
try{
Class c=Class.forName((String)jsch.getConfig("ecdsa-sha2-"+new String(name)));
final SignatureECDSA ecdsa=(SignatureECDSA)(c.newInstance());
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){
@@ -343,6 +395,11 @@ public class KeyPairECDSA extends KeyPair{
return null;
}
@Override
public Signature getVerifier(String alg){
return getVerifier();
}
static KeyPair fromSSHAgent(JSch jsch, Buffer buf) throws JSchException {
byte[][] tmp = buf.getBytes(5, "invalid key format");
@@ -357,17 +414,18 @@ public class KeyPairECDSA extends KeyPair{
name,
r_array, s_array,
prv_array);
kpair.publicKeyComment = new String(tmp[4]);
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-"+new String(name)));
buf.putString(Util.str2byte("ecdsa-sha2-"+Util.byte2str(name)));
buf.putString(name);
buf.putString(toPoint(r_array, s_array));
buf.putString(prv_array);
@@ -401,6 +459,7 @@ public class KeyPairECDSA extends KeyPair{
return tmp;
}
@Override
public void dispose(){
super.dispose();
Util.bzero(prv_array);

View File

@@ -0,0 +1,68 @@
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
/*
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 jsch){
this(jsch, null, null);
}
KeyPairEd25519(JSch jsch,
byte[] pub_array,
byte[] prv_array){
super(jsch, 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 jsch, 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(jsch, pub_array, prv_array);
kpair.publicKeyComment = Util.byte2str(tmp[3]);
kpair.vendor=VENDOR_OPENSSH;
return kpair;
}
}

View File

@@ -0,0 +1,68 @@
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
/*
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 jsch){
this(jsch, null, null);
}
KeyPairEd448(JSch jsch,
byte[] pub_array,
byte[] prv_array){
super(jsch, 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 jsch, 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(jsch, pub_array, prv_array);
kpair.publicKeyComment = Util.byte2str(tmp[3]);
kpair.vendor=VENDOR_OPENSSH;
return kpair;
}
}

View File

@@ -0,0 +1,191 @@
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
/*
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 jsch,
byte[] pub_array,
byte[] prv_array){
super(jsch);
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){
//System.err.println("KeyPairEdDSA: "+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){
// Only OPENSSH Key v1 Format supported for EdDSA keys
if(vendor != VENDOR_OPENSSH_V1) return false;
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){
//System.err.println(e);
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){
}
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){
}
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);
}
}

View File

@@ -0,0 +1,36 @@
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
/*
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();
}

View File

@@ -0,0 +1,34 @@
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
/*
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 KeyPairGenXEC{
void init(String name) throws Exception;
}

View File

@@ -32,7 +32,7 @@ package com.jcraft.jsch;
import java.util.Vector;
import java.math.BigInteger;
public class KeyPairPKCS8 extends KeyPair {
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
@@ -75,23 +75,28 @@ public class KeyPairPKCS8 extends KeyPair {
private KeyPair kpair = null;
public KeyPairPKCS8(JSch jsch){
KeyPairPKCS8(JSch jsch){
super(jsch);
}
@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
@@ -109,7 +114,7 @@ public class KeyPairPKCS8 extends KeyPair {
*/
try{
Vector values = new Vector();
Vector<byte[]> values = new Vector<>();
ASN1[] contents = null;
ASN1 asn1 = new ASN1(plain);
@@ -163,10 +168,10 @@ public class KeyPairPKCS8 extends KeyPair {
values.addElement(asn1.getContent());
}
byte[] P_array = (byte[])values.elementAt(0);
byte[] Q_array = (byte[])values.elementAt(1);
byte[] G_array = (byte[])values.elementAt(2);
byte[] prv_array = (byte[])values.elementAt(3);
byte[] P_array = values.elementAt(0);
byte[] Q_array = values.elementAt(1);
byte[] G_array = values.elementAt(2);
byte[] prv_array = values.elementAt(3);
// Y = g^X mode p
byte[] pub_array =
(new BigInteger(G_array)).
@@ -195,29 +200,47 @@ public class KeyPairPKCS8 extends KeyPair {
return kpair != null;
}
@Override
public byte[] getPublicKeyBlob(){
return kpair.getPublicKeyBlob();
}
@Override
byte[] getKeyTypeName(){ return kpair.getKeyTypeName();}
@Override
public int getKeyType(){return kpair.getKeyType();}
@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;
@@ -300,8 +323,8 @@ or
byte[] key=null;
try{
Class c=Class.forName((String)jsch.getConfig("pbkdf"));
PBKDF tmp=(PBKDF)(c.newInstance());
Class<? extends PBKDF> c=Class.forName(JSch.getConfig("pbkdf")).asSubclass(PBKDF.class);
PBKDF tmp=c.getDeclaredConstructor().newInstance();
key = tmp.getKey(_passphrase, salt, iterations, cipher.getBlockSize());
}
catch(Exception ee){
@@ -343,11 +366,11 @@ or
else if(Util.array_equals(id, aes256cbc)){
name="aes256-cbc";
}
Class c=Class.forName((String)jsch.getConfig(name));
cipher=(Cipher)(c.newInstance());
Class<? extends Cipher> c=Class.forName(JSch.getConfig(name)).asSubclass(Cipher.class);
cipher=c.getDeclaredConstructor().newInstance();
}
catch(Exception e){
if(JSch.getLogger().isEnabled(Logger.FATAL)){
if(jsch.getInstanceLogger().isEnabled(Logger.FATAL)){
String message="";
if(name==null){
message="unknown oid: "+Util.toHex(id);
@@ -355,7 +378,7 @@ or
else {
message="function "+name+" is not supported";
}
JSch.getLogger().log(Logger.FATAL, "PKCS8: "+message);
jsch.getInstanceLogger().log(Logger.FATAL, "PKCS8: "+message);
}
}
return cipher;

View File

@@ -31,7 +31,7 @@ package com.jcraft.jsch;
import java.math.BigInteger;
public class KeyPairRSA extends KeyPair{
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)
@@ -44,11 +44,11 @@ public class KeyPairRSA extends KeyPair{
private int key_size=1024;
public KeyPairRSA(JSch jsch){
KeyPairRSA(JSch jsch){
this(jsch, null, null, null);
}
public KeyPairRSA(JSch jsch,
KeyPairRSA(JSch jsch,
byte[] n_array,
byte[] pub_array,
byte[] prv_array){
@@ -57,15 +57,16 @@ public class KeyPairRSA extends KeyPair{
this.pub_array = pub_array;
this.prv_array = prv_array;
if(n_array!=null){
key_size = (new java.math.BigInteger(n_array)).bitLength();
key_size = (new BigInteger(n_array)).bitLength();
}
}
@Override
void generate(int key_size) throws JSchException{
this.key_size=key_size;
try{
Class c=Class.forName(jsch.getConfig("keypairgen.rsa"));
KeyPairGenRSA keypairgen=(KeyPairGenRSA)(c.newInstance());
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();
@@ -81,18 +82,19 @@ public class KeyPairRSA extends KeyPair{
}
catch(Exception e){
//System.err.println("KeyPairRSA: "+e);
if(e instanceof Throwable)
throw new JSchException(e.toString(), (Throwable)e);
throw new JSchException(e.toString());
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
@@ -123,6 +125,7 @@ public class KeyPairRSA extends KeyPair{
return plain;
}
@Override
boolean parse(byte [] plain){
try{
@@ -160,7 +163,7 @@ public class KeyPairRSA extends KeyPair{
p_array=buf.getMPIntBits();
q_array=buf.getMPIntBits();
if(n_array!=null){
key_size = (new java.math.BigInteger(n_array)).bitLength();
key_size = (new BigInteger(n_array)).bitLength();
}
getEPArray();
@@ -172,6 +175,28 @@ public class KeyPairRSA extends KeyPair{
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)
getEPArray();
getEQArray();
return true;
}
/*
Key must be in the following ASN.1 DER encoding,
RSAPrivateKey ::= SEQUENCE {
@@ -285,7 +310,7 @@ public class KeyPairRSA extends KeyPair{
index+=length;
if(n_array!=null){
key_size = (new java.math.BigInteger(n_array)).bitLength();
key_size = (new BigInteger(n_array)).bitLength();
}
}
@@ -296,6 +321,7 @@ public class KeyPairRSA extends KeyPair{
return true;
}
@Override
public byte[] getPublicKeyBlob(){
byte[] foo=super.getPublicKeyBlob();
if(foo!=null) return foo;
@@ -309,24 +335,33 @@ public class KeyPairRSA extends KeyPair{
}
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 c=Class.forName((String)jsch.getConfig("signature.rsa"));
SignatureRSA rsa=(SignatureRSA)(c.newInstance());
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] = sshrsa;
tmp[0] = Util.str2byte(alg);
tmp[1] = sig;
return Buffer.fromBytes(tmp).buffer;
}
@@ -335,10 +370,16 @@ public class KeyPairRSA extends KeyPair{
return null;
}
@Override
public Signature getVerifier(){
return getVerifier("ssh-rsa");
}
@Override
public Signature getVerifier(String alg){
try{
Class c=Class.forName((String)jsch.getConfig("signature.rsa"));
SignatureRSA rsa=(SignatureRSA)(c.newInstance());
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){
@@ -367,11 +408,12 @@ public class KeyPairRSA extends KeyPair{
kpair.c_array = tmp[4]; // iqmp
kpair.p_array = tmp[5];
kpair.q_array = tmp[6];
kpair.publicKeyComment = new String(tmp[7]);
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.");
@@ -411,6 +453,7 @@ public class KeyPairRSA extends KeyPair{
return c_array;
}
@Override
public void dispose(){
super.dispose();
Util.bzero(prv_array);

View File

@@ -29,23 +29,29 @@ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package com.jcraft.jsch;
import java.io.*;
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;
public
class KnownHosts implements HostKeyRepository{
private static final String _known_hosts="known_hosts";
private JSch jsch=null;
private String known_hosts=null;
private java.util.Vector pool=null;
private Vector<HostKey> pool=null;
private MAC hmacsha1=null;
MAC hmacsha1;
KnownHosts(JSch jsch) {
super();
this.jsch=jsch;
this.hmacsha1 = getHMACSHA1();
pool=new java.util.Vector();
getHMACSHA1();
pool=new Vector<>();
}
void setKnownHosts(String filename) throws JSchException{
@@ -60,7 +66,7 @@ class KnownHosts implements HostKeyRepository{
}
void setKnownHosts(InputStream input) throws JSchException{
pool.removeAllElements();
StringBuffer sb=new StringBuffer();
StringBuilder sb=new StringBuilder();
byte i;
int j;
boolean error=false;
@@ -78,7 +84,7 @@ loop:
j=fis.read();
if(j==-1){
if(bufl==0){ break loop; }
else{ break; }
break;
}
if(j==0x0d){ continue; }
if(j==0x0a){ break; }
@@ -228,14 +234,12 @@ loop:
catch(Exception e){
if(e instanceof JSchException)
throw (JSchException)e;
if(e instanceof Throwable)
throw new JSchException(e.toString(), (Throwable)e);
throw new JSchException(e.toString());
throw new JSchException(e.toString(), e);
}
finally {
try{ input.close(); }
catch(IOException e){
throw new JSchException(e.toString(), (Throwable)e);
throw new JSchException(e.toString(), e);
}
}
}
@@ -244,8 +248,10 @@ loop:
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){
@@ -256,23 +262,22 @@ loop:
try {
hk = new HostKey(host, HostKey.GUESS, key);
}
catch(JSchException e){ // unsupported 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=(HostKey)(pool.elementAt(i));
HostKey _hk=pool.elementAt(i);
if(_hk.isMatched(host) && _hk.type==hk.type){
if(Util.array_equals(_hk.key, key)){
return OK;
}
else{
result=CHANGED;
}
}
}
}
if(result==NOT_INCLUDED &&
host.startsWith("[") &&
@@ -284,15 +289,16 @@ loop:
return result;
}
@Override
public void add(HostKey hostkey, UserInfo userinfo){
int type=hostkey.type;
String host=hostkey.getHost();
byte[] key=hostkey.key;
// byte[] key=hostkey.key;
HostKey hk=null;
synchronized(pool){
for(int i=0; i<pool.size(); i++){
hk=(HostKey)(pool.elementAt(i));
hk=pool.elementAt(i);
if(hk.isMatched(host) && hk.type==type){
/*
if(Util.array_equals(hk.key, key)){ return; }
@@ -313,51 +319,61 @@ loop:
pool.addElement(hk);
String bar=getKnownHostsRepositoryID();
if(bar!=null){
boolean foo=true;
File goo=new File(Util.checkTilde(bar));
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()){
foo=false;
doSync = false;
if (userinfo!=null) {
foo=userinfo.promptYesNo(bar+" does not exist.\n"+
doSync = userinfo.promptYesNo(khFilename +" does not exist.\n"+
"Are you sure you want to create it?"
);
goo=goo.getParentFile();
if(foo && goo!=null && !goo.exists()){
foo=userinfo.promptYesNo("The parent directory "+goo+" does not exist.\n"+
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(foo){
if(doSync){
if(!goo.mkdirs()){
userinfo.showMessage(goo+" has not been created.");
foo=false;
doSync=false;
}
else{
userinfo.showMessage(goo+" has been succesfully created.\nPlease check its access permission.");
}
}
}
if(goo==null)foo=false;
if(goo==null)doSync=false;
}
}
if(foo){
if(!doSync){
return;
}
try{
sync(bar);
}
catch(Exception e){ System.err.println("sync known_hosts: "+e); }
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){
java.util.ArrayList v = new java.util.ArrayList();
List<HostKey> v = new ArrayList<>();
for(int i=0; i<pool.size(); i++){
HostKey hk=(HostKey)pool.elementAt(i);
HostKey hk=pool.elementAt(i);
if(hk.type==HostKey.UNKNOWN) continue;
if(host==null ||
(hk.isMatched(host) &&
@@ -367,7 +383,7 @@ loop:
}
HostKey[] foo = new HostKey[v.size()];
for(int i=0; i<v.size(); i++){
foo[i] = (HostKey)v.get(i);
foo[i] = v.get(i);
}
if(host != null && host.startsWith("[") && host.indexOf("]:")>1){
HostKey[] tmp =
@@ -382,23 +398,26 @@ loop:
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=(HostKey)(pool.elementAt(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(hosts.equals(host) ||
if(host == null || hosts.equals(host) ||
((hk instanceof HashedHostKey) &&
((HashedHostKey)hk).isHashed())){
pool.removeElement(hk);
i--;
}
else{
hk.host=deleteSubString(hosts, host);
@@ -412,34 +431,44 @@ loop:
}
}
protected void sync() throws IOException {
void sync() throws IOException {
if(known_hosts!=null)
sync(known_hosts);
}
protected synchronized void sync(String foo) throws IOException {
synchronized void sync(String foo) throws IOException {
if(foo==null) return;
FileOutputStream fos=new FileOutputStream(Util.checkTilde(foo));
try (FileOutputStream fos = new FileOutputStream(Util.checkTilde(foo))) {
dump(fos);
fos.close();
}
}
private static final byte[] space={(byte)0x20};
private static final byte[] cr=Util.str2byte("\n");
void dump(OutputStream out) throws IOException {
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=(HostKey)(pool.elementAt(i));
//hk.dump(out);
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(cr);
continue;
out.write(lf);
return;
}
if (marker.length() != 0) {
out.write(Util.str2byte(marker));
@@ -450,20 +479,15 @@ loop:
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(cr);
}
}
}
catch(Exception e){
System.err.println(e);
}
out.write(lf);
}
private String deleteSubString(String hosts, String host){
String deleteSubString(String hosts, String host){
int i=0;
int hostlen=host.length();
int hostslen=hosts.length();
@@ -483,18 +507,24 @@ loop:
return hosts;
}
private MAC getHMACSHA1(){
MAC getHMACSHA1() throws IllegalArgumentException {
if (hmacsha1 == null){
hmacsha1 = createHMAC(JSch.getConfig("hmac-sha1"));
}
return hmacsha1;
}
MAC createHMAC(String hmacClassname) throws IllegalArgumentException {
try{
Class c=Class.forName(jsch.getConfig("hmac-sha1"));
hmacsha1=(MAC)(c.newInstance());
Class<? extends MAC> c=Class.forName(hmacClassname).asSubclass(MAC.class);
return c.getDeclaredConstructor().newInstance();
}
catch(Exception e){
System.err.println("hmacsha1: "+e);
jsch.getInstanceLogger().log(Logger.ERROR, "unable to instantiate HMAC-class " + hmacClassname, e);
throw new IllegalArgumentException("instantiation of " + hmacClassname + " lead to an error", e);
}
}
return hmacsha1;
}
HostKey createHashedHostKey(String host, byte[]key) throws JSchException {
HashedHostKey hhk=new HashedHostKey(host, key);
@@ -524,8 +554,8 @@ loop:
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());
if(salt.length!=20 || // block size of hmac-sha1
hash.length!=20){
int blockSize = hmacsha1.getBlockSize();
if (salt.length!=blockSize || hash.length!=blockSize) {
salt=null;
hash=null;
return;
@@ -534,23 +564,23 @@ loop:
}
}
@Override
boolean isMatched(String _host){
if(!hashed){
return super.isMatched(_host);
}
MAC macsha1=getHMACSHA1();
try{
synchronized(macsha1){
macsha1.init(salt);
synchronized(hmacsha1){
hmacsha1.init(salt);
byte[] foo=Util.str2byte(_host);
macsha1.update(foo, 0, foo.length);
byte[] bar=new byte[macsha1.getBlockSize()];
macsha1.doFinal(bar, 0);
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){
System.out.println(e);
jsch.getInstanceLogger().log(Logger.ERROR, "an error occurred while trying to check hash for host " + _host, e);
}
return false;
}
@@ -562,27 +592,30 @@ loop:
void hash(){
if(hashed)
return;
MAC macsha1=getHMACSHA1();
if(salt==null){
Random random=Session.random;
synchronized(random){
salt=new byte[macsha1.getBlockSize()];
salt=new byte[hmacsha1.getBlockSize()];
random.fill(salt, 0, salt.length);
}
}
try{
synchronized(macsha1){
macsha1.init(salt);
synchronized(hmacsha1){
hmacsha1.init(salt);
byte[] foo=Util.str2byte(host);
macsha1.update(foo, 0, foo.length);
hash=new byte[macsha1.getBlockSize()];
macsha1.doFinal(hash, 0);
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))+
HASH_DELIM+Util.byte2str(Util.toBase64(hash, 0, hash.length));
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;
}
}

View File

@@ -34,24 +34,27 @@ import java.util.Vector;
class LocalIdentityRepository implements IdentityRepository {
private static final String name = "Local Identity Repository";
private Vector identities = new Vector();
private Vector<Identity> identities = new Vector<>();
private JSch jsch;
LocalIdentityRepository(JSch jsch){
this.jsch = jsch;
}
@Override
public String getName(){
return name;
}
@Override
public int getStatus(){
return RUNNING;
}
public synchronized Vector getIdentities() {
@Override
public synchronized Vector<Identity> getIdentities() {
removeDupulicates();
Vector v = new Vector();
Vector<Identity> v = new Vector<>();
for(int i=0; i<identities.size(); i++){
v.addElement(identities.elementAt(i));
}
@@ -66,10 +69,10 @@ class LocalIdentityRepository implements IdentityRepository {
return;
}
for(int i = 0; i<identities.size(); i++){
byte[] blob2 = ((Identity)identities.elementAt(i)).getPublicKeyBlob();
byte[] blob2 = identities.elementAt(i).getPublicKeyBlob();
if(blob2 != null && Util.array_equals(blob1, blob2)){
if(!identity.isEncrypted() &&
((Identity)identities.elementAt(i)).isEncrypted()){
identities.elementAt(i).isEncrypted()){
remove(blob2);
}
else {
@@ -81,6 +84,7 @@ class LocalIdentityRepository implements IdentityRepository {
}
}
@Override
public synchronized boolean add(byte[] identity) {
try{
Identity _identity =
@@ -103,10 +107,11 @@ class LocalIdentityRepository implements IdentityRepository {
}
}
@Override
public synchronized boolean remove(byte[] blob) {
if(blob == null) return false;
for(int i=0; i<identities.size(); i++) {
Identity _identity = (Identity)(identities.elementAt(i));
Identity _identity = identities.elementAt(i);
byte[] _blob = _identity.getPublicKeyBlob();
if(_blob == null || !Util.array_equals(blob, _blob))
continue;
@@ -117,24 +122,25 @@ class LocalIdentityRepository implements IdentityRepository {
return false;
}
@Override
public synchronized void removeAll() {
for(int i=0; i<identities.size(); i++) {
Identity identity=(Identity)(identities.elementAt(i));
Identity identity=identities.elementAt(i);
identity.clear();
}
identities.removeAllElements();
}
private void removeDupulicates(){
Vector v = new Vector();
Vector<byte[]> v = new Vector<>();
int len = identities.size();
if(len == 0) return;
for(int i=0; i<len; i++){
Identity foo = (Identity)identities.elementAt(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 = (Identity)identities.elementAt(j);
Identity bar = identities.elementAt(j);
byte[] bar_blob = bar.getPublicKeyBlob();
if(bar_blob == null) continue;
if(Util.array_equals(foo_blob, bar_blob) &&
@@ -145,7 +151,7 @@ class LocalIdentityRepository implements IdentityRepository {
}
}
for(int i=0; i<v.size(); i++){
remove((byte[])v.elementAt(i));
remove(v.elementAt(i));
}
}
}

View File

@@ -29,6 +29,9 @@ 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;
@@ -41,6 +44,20 @@ public interface Logger{
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;}

View File

@@ -36,4 +36,5 @@ public interface MAC{
void update(byte[] foo, int start, int len);
void update(int foo);
void doFinal(byte[] buf, int offset);
default boolean isEtM() {return false;}
}

View File

@@ -29,14 +29,20 @@ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package com.jcraft.jsch;
import java.io.InputStream;
import java.io.Reader;
import java.io.StringReader;
import java.io.FileReader;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.Reader;
import java.io.StringReader;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.Hashtable;
import java.util.List;
import java.util.Set;
import java.util.Vector;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
* This class implements ConfigRepository interface, and parses
@@ -47,6 +53,8 @@ import java.util.Vector;
* <li>Hostname</li>
* <li>Port</li>
* <li>PreferredAuthentications</li>
* <li>PubkeyAcceptedAlgorithms</li>
* <li>FingerprintHash</li>
* <li>IdentityFile</li>
* <li>NumberOfPasswordPrompts</li>
* <li>ConnectTimeout</li>
@@ -70,6 +78,10 @@ import java.util.Vector;
*/
public class OpenSSHConfig implements ConfigRepository {
private static final Set<String> keysWithListAdoption = Stream
.of("KexAlgorithms", "Ciphers","HostKeyAlgorithms", "MACs", "PubkeyAcceptedAlgorithms", "PubkeyAcceptedKeyTypes")
.map(String::toUpperCase).collect(Collectors.toSet());
/**
* Parses the given string, and returns an instance of ConfigRepository.
*
@@ -77,12 +89,10 @@ public class OpenSSHConfig implements ConfigRepository {
* @return an instanceof OpenSSHConfig
*/
public static OpenSSHConfig parse(String conf) throws IOException {
Reader r = new StringReader(conf);
try {
return new OpenSSHConfig(r);
try(Reader r = new StringReader(conf)) {
try(BufferedReader br = new BufferedReader(r)) {
return new OpenSSHConfig(br);
}
finally {
r.close();
}
}
@@ -93,27 +103,21 @@ public class OpenSSHConfig implements ConfigRepository {
* @return an instanceof OpenSSHConfig
*/
public static OpenSSHConfig parseFile(String file) throws IOException {
Reader r = new FileReader(Util.checkTilde(file));
try {
return new OpenSSHConfig(r);
}
finally {
r.close();
try(BufferedReader br = Files.newBufferedReader(Paths.get(Util.checkTilde(file)), StandardCharsets.UTF_8)) {
return new OpenSSHConfig(br);
}
}
OpenSSHConfig(Reader r) throws IOException {
_parse(r);
OpenSSHConfig(BufferedReader br) throws IOException {
_parse(br);
}
private final Hashtable config = new Hashtable();
private final Vector hosts = new Vector();
private void _parse(Reader r) throws IOException {
BufferedReader br = new BufferedReader(r);
private final Hashtable<String, Vector<String[]>> config = new Hashtable<>();
private final Vector<String> hosts = new Vector<>();
private void _parse(BufferedReader br) throws IOException {
String host = "";
Vector/*<String[]>*/ kv = new Vector();
Vector<String[]> kv = new Vector<>();
String l = null;
while((l = br.readLine()) != null){
@@ -128,11 +132,11 @@ public class OpenSSHConfig implements ConfigRepository {
if(key_value.length <= 1)
continue;
if(key_value[0].equals("Host")){
if(key_value[0].equalsIgnoreCase("Host")){
config.put(host, kv);
hosts.addElement(host);
host = key_value[1];
kv = new Vector();
kv = new Vector<>();
}
else {
kv.addElement(key_value);
@@ -142,11 +146,21 @@ public class OpenSSHConfig implements ConfigRepository {
hosts.addElement(host);
}
@Override
public Config getConfig(String host) {
return new MyConfig(host);
}
private static final Hashtable keymap = new Hashtable();
/**
* Returns mapping of jsch config property names to OpenSSH property names.
*
* @return map
*/
static Hashtable<String, String> getKeymap() {
return keymap;
}
private static final Hashtable<String, String> keymap = new Hashtable<>();
static {
keymap.put("kex", "KexAlgorithms");
keymap.put("server_host_key", "HostKeyAlgorithms");
@@ -163,7 +177,7 @@ public class OpenSSHConfig implements ConfigRepository {
class MyConfig implements Config {
private String host;
private Vector _configs = new Vector();
private Vector<Vector<String[]>> _configs = new Vector<>();
MyConfig(String host){
this.host = host;
@@ -173,7 +187,7 @@ public class OpenSSHConfig implements ConfigRepository {
byte[] _host = Util.str2byte(host);
if(hosts.size() > 1){
for(int i = 1; i < hosts.size(); i++){
String patterns[] = ((String)hosts.elementAt(i)).split("[ \t]");
String patterns[] = hosts.elementAt(i).split("[ \t]");
for(int j = 0; j < patterns.length; j++){
boolean negate = false;
String foo = patterns[j].trim();
@@ -183,11 +197,11 @@ public class OpenSSHConfig implements ConfigRepository {
}
if(Util.glob(Util.str2byte(foo), _host)){
if(!negate){
_configs.addElement(config.get((String)hosts.elementAt(i)));
_configs.addElement(config.get(hosts.elementAt(i)));
}
}
else if(negate){
_configs.addElement(config.get((String)hosts.elementAt(i)));
_configs.addElement(config.get(hosts.elementAt(i)));
}
}
}
@@ -195,15 +209,16 @@ public class OpenSSHConfig implements ConfigRepository {
}
private String find(String key) {
String originalKey=key;
if(keymap.get(key)!=null) {
key = (String)keymap.get(key);
key = keymap.get(key);
}
key = key.toUpperCase();
String value = null;
for(int i = 0; i < _configs.size(); i++) {
Vector v = (Vector)_configs.elementAt(i);
Vector<String[]> v = _configs.elementAt(i);
for(int j = 0; j < v.size(); j++) {
String[] kv = (String[])v.elementAt(j);
String[] kv = v.elementAt(j);
if(kv[0].toUpperCase().equals(key)) {
value = kv[1];
break;
@@ -226,16 +241,34 @@ public class OpenSSHConfig implements ConfigRepository {
}
}
*/
if (keysWithListAdoption.contains(key) && value != null && (value.startsWith("+") || value.startsWith("-") || value.startsWith("^"))) {
String origConfig = JSch.getConfig(originalKey).trim();
if (value.startsWith("+")) {
value=origConfig + "," + value.substring(1).trim();
} else if (value.startsWith("-")) {
List<String> algList = Arrays.stream(Util.split(origConfig,",")).collect(Collectors.toList());
for (String alg : Util.split(value.substring(1).trim(),",")) {
algList.remove(alg.trim());
}
value = String.join(",", algList);
} else if (value.startsWith("^")) {
value = value.substring(1).trim() + "," + origConfig;
}
}
return value;
}
private String[] multiFind(String key) {
key = key.toUpperCase();
Vector value = new Vector();
Vector<String> value = new Vector<>();
for(int i = 0; i < _configs.size(); i++) {
Vector v = (Vector)_configs.elementAt(i);
Vector<String[]> v = _configs.elementAt(i);
for(int j = 0; j < v.size(); j++) {
String[] kv = (String[])v.elementAt(j);
String[] kv = v.elementAt(j);
if(kv[0].toUpperCase().equals(key)) {
String foo = kv[1];
if(foo != null) {
@@ -250,8 +283,11 @@ public class OpenSSHConfig implements ConfigRepository {
return result;
}
@Override
public String getHostname(){ return find("Hostname"); }
@Override
public String getUser(){ return find("User"); }
@Override
public int getPort(){
String foo = find("Port");
int port = -1;
@@ -263,6 +299,7 @@ public class OpenSSHConfig implements ConfigRepository {
}
return port;
}
@Override
public String getValue(String key){
if(key.equals("compression.s2c") ||
key.equals("compression.c2s")) {
@@ -273,6 +310,7 @@ public class OpenSSHConfig implements ConfigRepository {
}
return find(key);
}
@Override
public String[] getValues(String key){ return multiFind(key); }
}
}

View File

@@ -29,26 +29,32 @@ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package com.jcraft.jsch;
public class Packet{
class Packet{
private static Random random=null;
static void setRandom(Random foo){ random=foo;}
Buffer buffer;
byte[] ba4=new byte[4];
public Packet(Buffer buffer){
Packet(Buffer buffer){
this.buffer=buffer;
}
public void reset(){
void reset(){
buffer.index=5;
}
void padding(int bsize){
void padding(int bsize, boolean includePktLen){
int len=buffer.index;
if(!includePktLen){
len-=4;
}
int pad=(-len)&(bsize-1);
if(pad<bsize){
pad+=bsize;
}
len=len+pad-4;
len+=pad;
if(includePktLen){
len-=4;
}
ba4[0]=(byte)(len>>>24);
ba4[1]=(byte)(len>>>16);
ba4[2]=(byte)(len>>>8);

View File

@@ -29,11 +29,16 @@ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package com.jcraft.jsch;
import java.net.*;
import java.io.*;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.Vector;
class PortWatcher implements Runnable{
private static java.util.Vector pool=new java.util.Vector();
class PortWatcher{
private static Vector<PortWatcher> pool=new Vector<>();
private static InetAddress anyLocalAddress=null;
static{
// 0.0.0.0
@@ -47,6 +52,7 @@ class PortWatcher implements Runnable{
}
}
Session session;
int lport;
int rport;
@@ -55,12 +61,38 @@ class PortWatcher implements Runnable{
Runnable thread;
ServerSocket ss;
int connectTimeout=0;
private String socketPath;
PortWatcher(Session session, String address, int lport, String socketPath, ServerSocketFactory ssf) throws JSchException {
this.session=session;
this.lport=lport;
this.socketPath = socketPath;
bindLocalPort(address, lport, ssf);
}
private void bindLocalPort(String address, int lport, ServerSocketFactory ssf) throws JSchException {
try{
boundaddress= InetAddress.getByName(address);
ss=(ssf==null) ?
new ServerSocket(lport, 0, boundaddress) :
ssf.createServerSocket(lport, 0, boundaddress);
}
catch(Exception e){
String message="PortForwardingL: local port "+address+":"+lport+" cannot be bound.";
throw new JSchException(message, e);
}
if(lport==0){
int assigned=ss.getLocalPort();
if(assigned!=-1)
this.lport=assigned;
}
}
static String[] getPortForwarding(Session session){
java.util.Vector foo=new java.util.Vector();
Vector<String> foo=new Vector<>();
synchronized(pool){
for(int i=0; i<pool.size(); i++){
PortWatcher p=(PortWatcher)(pool.elementAt(i));
PortWatcher p=pool.elementAt(i);
if(p.session==session){
foo.addElement(p.lport+":"+p.host+":"+p.rport);
}
@@ -68,7 +100,7 @@ class PortWatcher implements Runnable{
}
String[] bar=new String[foo.size()];
for(int i=0; i<foo.size(); i++){
bar[i]=(String)(foo.elementAt(i));
bar[i]=foo.elementAt(i);
}
return bar;
}
@@ -82,7 +114,7 @@ class PortWatcher implements Runnable{
}
synchronized(pool){
for(int i=0; i<pool.size(); i++){
PortWatcher p=(PortWatcher)(pool.elementAt(i));
PortWatcher p=pool.elementAt(i);
if(p.session==session && p.lport==lport){
if(/*p.boundaddress.isAnyLocalAddress() ||*/
(anyLocalAddress!=null && p.boundaddress.equals(anyLocalAddress)) ||
@@ -125,7 +157,7 @@ class PortWatcher implements Runnable{
PortWatcher[] foo=new PortWatcher[pool.size()];
int count=0;
for(int i=0; i<pool.size(); i++){
PortWatcher p=(PortWatcher)(pool.elementAt(i));
PortWatcher p=pool.elementAt(i);
if(p.session==session) {
p.delete();
foo[count++]=p;
@@ -145,48 +177,55 @@ class PortWatcher implements Runnable{
this.lport=lport;
this.host=host;
this.rport=rport;
try{
boundaddress=InetAddress.getByName(address);
ss=(factory==null) ?
new ServerSocket(lport, 0, boundaddress) :
factory.createServerSocket(lport, 0, boundaddress);
}
catch(Exception e){
//System.err.println(e);
String message="PortForwardingL: local port "+address+":"+lport+" cannot be bound.";
if(e instanceof Throwable)
throw new JSchException(message, (Throwable)e);
throw new JSchException(message);
}
if(lport==0){
int assigned=ss.getLocalPort();
if(assigned!=-1)
this.lport=assigned;
}
bindLocalPort(address, lport, factory);
}
public void run(){
thread=this;
public static PortWatcher addSocket(Session session, String bindAddress, int lport, String socketPath, ServerSocketFactory ssf) throws JSchException {
String address = normalize(bindAddress);
if(getPort(session, address, lport)!=null){
throw new JSchException("PortForwardingL: local port "+ address+":"+lport+" is already registered.");
}
PortWatcher pw=new PortWatcher(session, address, lport, socketPath, ssf);
pool.addElement(pw);
return pw;
}
void run(){
thread=this::run;
try{
while(thread!=null){
Socket socket=ss.accept();
socket.setTcpNoDelay(true);
InputStream in=socket.getInputStream();
OutputStream out=socket.getOutputStream();
ChannelDirectTCPIP channel=new ChannelDirectTCPIP();
if(socketPath!=null && socketPath.length()>0){
ChannelDirectStreamLocal channel = new ChannelDirectStreamLocal();
channel.setSession(session);
channel.init();
channel.setInputStream(in);
channel.setOutputStream(out);
session.addChannel(channel);
((ChannelDirectTCPIP)channel).setHost(host);
((ChannelDirectTCPIP)channel).setPort(rport);
((ChannelDirectTCPIP)channel).setOrgIPAddress(socket.getInetAddress().getHostAddress());
((ChannelDirectTCPIP)channel).setOrgPort(socket.getPort());
channel.setSocketPath(socketPath);
channel.setOrgIPAddress(socket.getInetAddress().getHostAddress());
channel.setOrgPort(socket.getPort());
channel.connect(connectTimeout);
} else {
ChannelDirectTCPIP channel = new ChannelDirectTCPIP();
channel.setSession(session);
channel.init();
channel.setInputStream(in);
channel.setOutputStream(out);
session.addChannel(channel);
channel.setHost(host);
channel.setPort(rport);
channel.setOrgIPAddress(socket.getInetAddress().getHostAddress());
channel.setOrgPort(socket.getPort());
channel.connect(connectTimeout);
if (channel.exitstatus != -1) {
}
}
}
}
catch(Exception e){
//System.err.println("! "+e);
}

View File

@@ -65,6 +65,7 @@ public class ProxyHTTP implements Proxy{
this.user=user;
this.passwd=passwd;
}
@Override
public void connect(SocketFactory socket_factory, String host, int port, int timeout) throws JSchException{
try{
if(socket_factory==null){
@@ -86,7 +87,7 @@ public class ProxyHTTP implements Proxy{
if(user!=null && passwd!=null){
byte[] code=Util.str2byte(user+":"+passwd);
code=Util.toBase64(code, 0, code.length);
code=Util.toBase64(code, 0, code.length, true);
out.write(Util.str2byte("Proxy-Authorization: Basic "));
out.write(code);
out.write(Util.str2byte("\r\n"));
@@ -97,7 +98,7 @@ public class ProxyHTTP implements Proxy{
int foo=0;
StringBuffer sb=new StringBuffer();
StringBuilder sb=new StringBuilder();
while(foo>=0){
foo=in.read(); if(foo!=13){sb.append((char)foo); continue;}
foo=in.read(); if(foo!=10){continue;}
@@ -154,14 +155,16 @@ public class ProxyHTTP implements Proxy{
catch(Exception eee){
}
String message="ProxyHTTP: "+e.toString();
if(e instanceof Throwable)
throw new JSchException(message, (Throwable)e);
throw new JSchException(message);
throw new JSchException(message, e);
}
}
@Override
public InputStream getInputStream(){ return in; }
@Override
public OutputStream getOutputStream(){ return out; }
@Override
public Socket getSocket(){ return socket; }
@Override
public void close(){
try{
if(in!=null)in.close();

View File

@@ -70,6 +70,7 @@ public class ProxySOCKS4 implements Proxy{
this.user=user;
this.passwd=passwd;
}
@Override
public void connect(SocketFactory socket_factory, String host, int port, int timeout) throws JSchException{
try{
if(socket_factory==null){
@@ -188,12 +189,16 @@ public class ProxySOCKS4 implements Proxy{
try{ if(socket!=null)socket.close(); }
catch(Exception eee){
}
throw new JSchException("ProxySOCKS4: "+e.toString());
throw new JSchException("ProxySOCKS4: "+e.toString(), e);
}
}
@Override
public InputStream getInputStream(){ return in; }
@Override
public OutputStream getOutputStream(){ return out; }
@Override
public Socket getSocket(){ return socket; }
@Override
public void close(){
try{
if(in!=null)in.close();

View File

@@ -70,6 +70,7 @@ public class ProxySOCKS5 implements Proxy{
this.user=user;
this.passwd=passwd;
}
@Override
public void connect(SocketFactory socket_factory, String host, int port, int timeout) throws JSchException{
try{
if(socket_factory==null){
@@ -313,14 +314,16 @@ public class ProxySOCKS5 implements Proxy{
catch(Exception eee){
}
String message="ProxySOCKS5: "+e.toString();
if(e instanceof Throwable)
throw new JSchException(message, (Throwable)e);
throw new JSchException(message);
throw new JSchException(message, e);
}
}
@Override
public InputStream getInputStream(){ return in; }
@Override
public OutputStream getOutputStream(){ return out; }
@Override
public Socket getSocket(){ return socket; }
@Override
public void close(){
try{
if(in!=null)in.close();

View File

@@ -30,6 +30,7 @@ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package com.jcraft.jsch;
class RequestAgentForwarding extends Request{
@Override
public void request(Session session, Channel channel) throws Exception{
super.request(session, channel);

View File

@@ -36,8 +36,10 @@ class RequestEnv extends Request{
this.name=name;
this.value=value;
}
@Override
public void request(Session session, Channel channel) throws Exception{
super.request(session, channel);
setReply(false);
Buffer buf=new Buffer();
Packet packet=new Packet(buf);
@@ -46,7 +48,7 @@ class RequestEnv extends Request{
buf.putByte((byte) Session.SSH_MSG_CHANNEL_REQUEST);
buf.putInt(channel.getRecipient());
buf.putString(Util.str2byte("env"));
buf.putByte((byte)(waitForReply() ? 1 : 0));
buf.putByte((byte) 0);
buf.putString(name);
buf.putString(value);
write(packet);

View File

@@ -34,6 +34,7 @@ class RequestExec extends Request{
RequestExec(byte[] command){
this.command=command;
}
@Override
public void request(Session session, Channel channel) throws Exception{
super.request(session, channel);

View File

@@ -56,6 +56,7 @@ class RequestPtyReq extends Request{
this.thp=thp;
}
@Override
public void request(Session session, Channel channel) throws Exception{
super.request(session, channel);

View File

@@ -29,10 +29,11 @@ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package com.jcraft.jsch;
public class RequestSftp extends Request{
class RequestSftp extends Request{
RequestSftp(){
setReply(true);
}
@Override
public void request(Session session, Channel channel) throws Exception{
super.request(session, channel);

View File

@@ -30,6 +30,7 @@ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package com.jcraft.jsch;
class RequestShell extends Request{
@Override
public void request(Session session, Channel channel) throws Exception{
super.request(session, channel);

View File

@@ -32,6 +32,7 @@ package com.jcraft.jsch;
class RequestSignal extends Request{
private String signal="KILL";
public void setSignal(String foo){ signal=foo; }
@Override
public void request(Session session, Channel channel) throws Exception{
super.request(session, channel);

View File

@@ -29,13 +29,14 @@ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package com.jcraft.jsch;
public class RequestSubsystem extends Request{
class RequestSubsystem extends Request{
private String subsystem=null;
public void request(Session session, Channel channel, String subsystem, boolean want_reply) throws Exception{
setReply(want_reply);
this.subsystem=subsystem;
this.request(session, channel);
}
@Override
public void request(Session session, Channel channel) throws Exception{
super.request(session, channel);

View File

@@ -40,6 +40,7 @@ class RequestWindowChange extends Request{
this.width_pixels=wp;
this.height_pixels=hp;
}
@Override
public void request(Session session, Channel channel) throws Exception{
super.request(session, channel);

View File

@@ -33,6 +33,7 @@ class RequestX11 extends Request{
public void setCookie(String cookie){
ChannelX11.cookie=Util.str2byte(cookie);
}
@Override
public void request(Session session, Channel channel) throws Exception{
super.request(session, channel);

View File

@@ -70,7 +70,7 @@ public class SftpATTRS {
private static final int pmask = 0xFFF;
public String getPermissionsString() {
StringBuffer buf = new StringBuffer(10);
StringBuilder buf = new StringBuilder(10);
if(isDir()) buf.append('d');
else if(isLink()) buf.append('l');
@@ -279,6 +279,7 @@ public class SftpATTRS {
public int getMTime() { return mtime; }
public String[] getExtended() { return extended; }
@Override
public String toString() {
return (getPermissionsString()+" "+getUId()+" "+getGId()+" "+getSize()+" "+getMtimeString());
}

View File

@@ -30,22 +30,18 @@ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package com.jcraft.jsch;
public class SftpException extends Exception{
//private static final long serialVersionUID=-5616888495583253811L;
private static final long serialVersionUID=-1L;
public int id;
private Throwable cause=null;
public SftpException (int id, String message) {
super(message);
this.id=id;
}
public SftpException (int id, String message, Throwable e) {
super(message);
super(message, e);
this.id=id;
this.cause=e;
}
@Override
public String toString(){
return id+": "+getMessage();
}
public Throwable getCause(){
return this.cause;
}
}

View File

@@ -0,0 +1,35 @@
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
/*
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 SignatureEdDSA extends Signature {
void setPubKey(byte[] y_arr) throws Exception;
void setPrvKey(byte[] bytes) throws Exception;
}

View File

@@ -0,0 +1,40 @@
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
/*
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.io.IOException;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;
import java.nio.file.Path;
public interface USocketFactory {
SocketChannel connect(Path path) throws IOException;
ServerSocketChannel bind(Path path) throws IOException;
}

View File

@@ -0,0 +1,55 @@
/* -*-mode:java; c-basic-offset:2; indent-tabs-mode:nil -*- */
/*
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 com.jcraft.jsch.AgentProxyException;
import com.jcraft.jsch.USocketFactory;
import java.io.IOException;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;
import java.nio.file.Path;
public class UnixDomainSocketFactory implements USocketFactory {
public UnixDomainSocketFactory() throws AgentProxyException {
throw new AgentProxyException("UnixDomainSocketFactory requires Java16+.");
}
@Override
public SocketChannel connect(Path path) throws IOException {
throw new UnsupportedOperationException("UnixDomainSocketFactory requires Java16+.");
}
@Override
public ServerSocketChannel bind(Path path) throws IOException {
throw new UnsupportedOperationException("UnixDomainSocketFactory requires Java16+.");
}
}

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