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:
@@ -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;
|
||||
}
|
@@ -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() { }
|
||||
}
|
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
@@ -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;
|
||||
}
|
||||
}
|
@@ -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);
|
||||
}
|
||||
setH(md);
|
||||
public class AgentProxyException extends Exception {
|
||||
private static final long serialVersionUID=-1L;
|
||||
public AgentProxyException(String message){
|
||||
super(message);
|
||||
}
|
||||
|
||||
public String getName(){
|
||||
return name;
|
||||
public AgentProxyException(String message, Throwable e){
|
||||
super(message, e);
|
||||
}
|
||||
}
|
@@ -271,15 +271,15 @@ public class Buffer{
|
||||
int foo;
|
||||
for(int i=0; i<tmp_buffer_index; i++){
|
||||
foo=tmp_buffer[i]&0xff;
|
||||
System.err.print(chars[(foo>>>4)&0xf]);
|
||||
System.err.print(chars[foo&0xf]);
|
||||
System.err.print(chars[(foo>>>4)&0xf]);
|
||||
System.err.print(chars[foo&0xf]);
|
||||
if(i%16==15){
|
||||
System.err.println("");
|
||||
continue;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if(i>0 && i%2==1){
|
||||
System.err.print(" ");
|
||||
}
|
||||
}
|
||||
}
|
||||
System.err.println("");
|
||||
}
|
||||
|
@@ -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();
|
||||
}
|
||||
return null;
|
||||
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);
|
||||
@@ -546,14 +553,14 @@ public abstract class Channel implements Runnable{
|
||||
synchronized(pool){
|
||||
channels=new Channel[pool.size()];
|
||||
for(int i=0; i<pool.size(); i++){
|
||||
try{
|
||||
Channel c=((Channel)(pool.elementAt(i)));
|
||||
if(c.session==session){
|
||||
channels[count++]=c;
|
||||
}
|
||||
}
|
||||
catch(Exception e){
|
||||
}
|
||||
try{
|
||||
Channel c=pool.elementAt(i);
|
||||
if(c.session==session){
|
||||
channels[count++]=c;
|
||||
}
|
||||
}
|
||||
catch(Exception e){
|
||||
}
|
||||
}
|
||||
}
|
||||
for(int i=0; i<count; i++){
|
||||
@@ -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;
|
||||
|
@@ -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,7 +210,22 @@ class ChannelAgentForwarding extends Channel{
|
||||
byte[] signature=null;
|
||||
|
||||
if(identity!=null){
|
||||
signature=identity.getSignature(data);
|
||||
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){
|
||||
@@ -259,6 +279,7 @@ class ChannelAgentForwarding extends Channel{
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
void eof_remote(){
|
||||
super.eof_remote();
|
||||
eof();
|
||||
|
@@ -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;
|
||||
}
|
||||
}
|
@@ -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() +
|
||||
|
@@ -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();
|
||||
}
|
||||
}
|
||||
|
@@ -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));
|
||||
if(config instanceof ConfigDaemon)
|
||||
foo.addElement(config.allocated_rport+":"+config.target+":");
|
||||
else
|
||||
foo.addElement(config.allocated_rport+":"+config.target+":"+((ConfigLHost)config).lport);
|
||||
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;
|
||||
}
|
||||
@@ -263,13 +267,13 @@ public class ChannelForwardedTCPIP extends Channel{
|
||||
pool.removeElement(foo);
|
||||
if(address_to_bind==null){
|
||||
address_to_bind=foo.address_to_bind;
|
||||
}
|
||||
}
|
||||
if(address_to_bind==null){
|
||||
address_to_bind="0.0.0.0";
|
||||
}
|
||||
}
|
||||
|
||||
Buffer buf=new Buffer(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();
|
||||
}
|
||||
|
@@ -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);
|
||||
@@ -239,27 +242,27 @@ class ChannelSession extends Channel{
|
||||
int i=-1;
|
||||
try{
|
||||
while(isConnected() &&
|
||||
thread!=null &&
|
||||
thread!=null &&
|
||||
io!=null &&
|
||||
io.in!=null){
|
||||
i=io.in.read(buf.buffer,
|
||||
14,
|
||||
buf.buffer.length-14
|
||||
-Session.buffer_margin
|
||||
);
|
||||
if(i==0)continue;
|
||||
if(i==-1){
|
||||
eof();
|
||||
break;
|
||||
}
|
||||
if(close)break;
|
||||
);
|
||||
if(i==0)continue;
|
||||
if(i==-1){
|
||||
eof();
|
||||
break;
|
||||
}
|
||||
if(close)break;
|
||||
//System.out.println("write: "+i);
|
||||
packet.reset();
|
||||
buf.putByte((byte)Session.SSH_MSG_CHANNEL_DATA);
|
||||
buf.putInt(recipient);
|
||||
buf.putInt(i);
|
||||
buf.skip(i);
|
||||
getSession().write(packet, this, i);
|
||||
getSession().write(packet, this, i);
|
||||
}
|
||||
}
|
||||
catch(Exception e){
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -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);
|
||||
|
@@ -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{
|
||||
@@ -47,20 +46,18 @@ public class ChannelSubsystem extends ChannelSession{
|
||||
request.request(_session, this);
|
||||
}
|
||||
if(pty){
|
||||
request=new RequestPtyReq();
|
||||
request.request(_session, this);
|
||||
request=new RequestPtyReq();
|
||||
request.request(_session, this);
|
||||
}
|
||||
request=new RequestSubsystem();
|
||||
((RequestSubsystem)request).request(_session, this, subsystem, want_reply);
|
||||
}
|
||||
catch(Exception e){
|
||||
if(e instanceof JSchException){ throw (JSchException)e; }
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
@@ -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};
|
||||
@@ -64,21 +66,21 @@ class ChannelX11 extends Channel{
|
||||
cookie_hex=Util.str2byte(foo);
|
||||
cookie=new byte[16];
|
||||
for(int i=0; i<16; i++){
|
||||
cookie[i]=(byte)(((revtable(cookie_hex[i*2])<<4)&0xf0) |
|
||||
((revtable(cookie_hex[i*2+1]))&0xf));
|
||||
cookie[i]=(byte)(((revtable(cookie_hex[i*2])<<4)&0xf0) |
|
||||
((revtable(cookie_hex[i*2+1]))&0xf));
|
||||
}
|
||||
}
|
||||
static void setHost(String foo){ host=foo; }
|
||||
static void setPort(int foo){ port=foo; }
|
||||
static byte[] getFakedCookie(Session session){
|
||||
synchronized(faked_cookie_hex_pool){
|
||||
byte[] foo=(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];
|
||||
synchronized(random){
|
||||
random.fill(foo, 0, 16);
|
||||
}
|
||||
Random random=Session.random;
|
||||
foo=new byte[16];
|
||||
synchronized(random){
|
||||
random.fill(foo, 0, 16);
|
||||
}
|
||||
/*
|
||||
System.err.print("faked_cookie: ");
|
||||
for(int i=0; i<foo.length; i++){
|
||||
@@ -86,14 +88,14 @@ for(int i=0; i<foo.length; i++){
|
||||
}
|
||||
System.err.println("");
|
||||
*/
|
||||
faked_cookie_pool.put(session, foo);
|
||||
byte[] bar=new byte[32];
|
||||
for(int i=0; i<16; i++){
|
||||
bar[2*i]=table[(foo[i]>>>4)&0xf];
|
||||
bar[2*i+1]=table[(foo[i])&0xf];
|
||||
}
|
||||
faked_cookie_hex_pool.put(session, bar);
|
||||
foo=bar;
|
||||
faked_cookie_pool.put(session, foo);
|
||||
byte[] bar=new byte[32];
|
||||
for(int i=0; i<16; i++){
|
||||
bar[2*i]=table[(foo[i]>>>4)&0xf];
|
||||
bar[2*i+1]=table[(foo[i])&0xf];
|
||||
}
|
||||
faked_cookie_hex_pool.put(session, bar);
|
||||
foo=bar;
|
||||
}
|
||||
return foo;
|
||||
}
|
||||
@@ -130,7 +132,8 @@ System.err.println("");
|
||||
*/
|
||||
}
|
||||
|
||||
public void run(){
|
||||
@Override
|
||||
void run(){
|
||||
|
||||
try{
|
||||
socket=Util.createSocket(host, port, TIMEOUT);
|
||||
@@ -156,19 +159,19 @@ System.err.println("");
|
||||
io!=null &&
|
||||
io.in!=null){
|
||||
i=io.in.read(buf.buffer,
|
||||
14,
|
||||
buf.buffer.length-14-Session.buffer_margin);
|
||||
if(i<=0){
|
||||
eof();
|
||||
14,
|
||||
buf.buffer.length-14-Session.buffer_margin);
|
||||
if(i<=0){
|
||||
eof();
|
||||
break;
|
||||
}
|
||||
if(close)break;
|
||||
}
|
||||
if(close)break;
|
||||
packet.reset();
|
||||
buf.putByte((byte)Session.SSH_MSG_CHANNEL_DATA);
|
||||
buf.putInt(recipient);
|
||||
buf.putInt(i);
|
||||
buf.skip(i);
|
||||
getSession().write(packet, this, i);
|
||||
getSession().write(packet, this, i);
|
||||
}
|
||||
}
|
||||
catch(Exception e){
|
||||
@@ -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);
|
||||
@@ -217,7 +221,7 @@ System.err.println("");
|
||||
dlen=((dlen>>>8)&0xff)|((dlen<<8)&0xff00);
|
||||
}
|
||||
else{
|
||||
// ??
|
||||
// ??
|
||||
}
|
||||
|
||||
if(l<12+plen+((-plen)&3)+dlen)
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -249,7 +253,7 @@ System.err.println("");
|
||||
System.arraycopy(cookie, 0, foo, s+12+plen+((-plen)&3), dlen);
|
||||
}
|
||||
else{
|
||||
//System.err.println("wrong cookie");
|
||||
//System.err.println("wrong cookie");
|
||||
thread=null;
|
||||
eof();
|
||||
io.close();
|
||||
|
@@ -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;}
|
||||
}
|
||||
|
@@ -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; }
|
||||
}
|
||||
|
@@ -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);
|
||||
|
@@ -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; }
|
||||
};
|
||||
}
|
||||
|
@@ -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;
|
||||
}
|
||||
}
|
@@ -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;
|
||||
}
|
||||
}
|
@@ -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;
|
||||
|
@@ -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;
|
||||
|
@@ -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;
|
||||
|
@@ -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;
|
||||
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 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,9 +116,9 @@ 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);
|
||||
return false;
|
||||
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();
|
||||
@@ -135,7 +134,7 @@ public abstract class DHECN extends KeyExchange{
|
||||
// Section 3.2.2 of [SEC1]. If a key fails validation,
|
||||
// the key exchange MUST fail.
|
||||
if(!ecdh.validate(r_s[0], r_s[1])){
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
K = ecdh.getSecret(r_s[0], r_s[1]);
|
||||
@@ -171,7 +170,7 @@ public abstract class DHECN extends KeyExchange{
|
||||
i=0;
|
||||
j=0;
|
||||
j=((K_S[i++]<<24)&0xff000000)|((K_S[i++]<<16)&0x00ff0000)|
|
||||
((K_S[i++]<<8)&0x0000ff00)|((K_S[i++])&0x000000ff);
|
||||
((K_S[i++]<<8)&0x0000ff00)|((K_S[i++])&0x000000ff);
|
||||
String alg=Util.byte2str(K_S, i, j);
|
||||
i+=j;
|
||||
|
||||
@@ -183,5 +182,6 @@ public abstract class DHECN extends KeyExchange{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getState(){return state; }
|
||||
}
|
||||
|
@@ -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"; }
|
||||
}
|
||||
|
@@ -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"; }
|
||||
}
|
||||
|
@@ -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"; }
|
||||
}
|
@@ -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"; }
|
||||
}
|
@@ -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; }
|
||||
}
|
@@ -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"; }
|
||||
}
|
@@ -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"; }
|
||||
}
|
@@ -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"; }
|
||||
}
|
@@ -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; }
|
||||
}
|
@@ -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"; }
|
||||
}
|
@@ -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"; }
|
||||
}
|
@@ -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; }
|
||||
}
|
@@ -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"; }
|
||||
}
|
@@ -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"; }
|
||||
}
|
@@ -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;
|
||||
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 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){
|
||||
@@ -118,8 +122,8 @@ public class DHGEX extends KeyExchange{
|
||||
_buf.getByte();
|
||||
j=_buf.getByte();
|
||||
if(j!=SSH_MSG_KEX_DH_GEX_GROUP){
|
||||
System.err.println("type: must be SSH_MSG_KEX_DH_GEX_GROUP "+j);
|
||||
return false;
|
||||
System.err.println("type: must be SSH_MSG_KEX_DH_GEX_GROUP "+j);
|
||||
return false;
|
||||
}
|
||||
|
||||
p=_buf.getMPInt();
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
@@ -160,8 +164,8 @@ public class DHGEX extends KeyExchange{
|
||||
j=_buf.getByte();
|
||||
j=_buf.getByte();
|
||||
if(j!=SSH_MSG_KEX_DH_GEX_REPLY){
|
||||
System.err.println("type: must be SSH_MSG_KEX_DH_GEX_REPLY "+j);
|
||||
return false;
|
||||
System.err.println("type: must be SSH_MSG_KEX_DH_GEX_REPLY "+j);
|
||||
return false;
|
||||
}
|
||||
|
||||
K_S=_buf.getString();
|
||||
@@ -212,7 +216,7 @@ public class DHGEX extends KeyExchange{
|
||||
i=0;
|
||||
j=0;
|
||||
j=((K_S[i++]<<24)&0xff000000)|((K_S[i++]<<16)&0x00ff0000)|
|
||||
((K_S[i++]<<8)&0x0000ff00)|((K_S[i++])&0x000000ff);
|
||||
((K_S[i++]<<8)&0x0000ff00)|((K_S[i++])&0x000000ff);
|
||||
String alg=Util.byte2str(K_S, i, j);
|
||||
i+=j;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
@@ -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";
|
||||
}
|
||||
}
|
@@ -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";
|
||||
}
|
||||
}
|
@@ -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";
|
||||
}
|
||||
|
@@ -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";
|
||||
}
|
||||
}
|
@@ -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";
|
||||
}
|
||||
}
|
@@ -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; }
|
||||
}
|
@@ -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; }
|
||||
}
|
@@ -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 "";}
|
||||
}
|
||||
|
@@ -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; }
|
||||
@@ -132,7 +141,7 @@ public class HostKey{
|
||||
return hosts.regionMatches(true, i, _host, 0, hostlen);
|
||||
}
|
||||
if(hostlen==(j-i)){
|
||||
if(hosts.regionMatches(true, i, _host, 0, hostlen)) return true;
|
||||
if(hosts.regionMatches(true, i, _host, 0, hostlen)) return true;
|
||||
}
|
||||
i=j+1;
|
||||
}
|
||||
|
@@ -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();
|
||||
}
|
||||
@@ -81,7 +82,7 @@ public class IO{
|
||||
do{
|
||||
int completed = in.read(array, begin, length);
|
||||
if(completed<0){
|
||||
throw new IOException("End of IO Stream Read");
|
||||
throw new IOException("End of IO Stream Read");
|
||||
}
|
||||
begin+=completed;
|
||||
length-=completed;
|
||||
@@ -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();
|
||||
}
|
||||
|
@@ -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();
|
||||
|
||||
|
@@ -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;
|
||||
|
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -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");
|
||||
"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-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("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){
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -313,7 +402,7 @@ public class JSch{
|
||||
if(known_hosts==null) known_hosts=new KnownHosts(this);
|
||||
if(known_hosts instanceof KnownHosts){
|
||||
synchronized(known_hosts){
|
||||
((KnownHosts)known_hosts).setKnownHosts(filename);
|
||||
((KnownHosts)known_hosts).setKnownHosts(filename);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -333,7 +422,7 @@ public class JSch{
|
||||
if(known_hosts==null) known_hosts=new KnownHosts(this);
|
||||
if(known_hosts instanceof KnownHosts){
|
||||
synchronized(known_hosts){
|
||||
((KnownHosts)known_hosts).setKnownHosts(stream);
|
||||
((KnownHosts)known_hosts).setKnownHosts(stream);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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){
|
||||
config.put(key, 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
|
||||
*/
|
||||
@@ -583,8 +683,34 @@ public class JSch{
|
||||
if(logger==null) logger=DEVNULL;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@@ -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 "";
|
||||
}
|
||||
}
|
||||
}
|
@@ -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();
|
||||
|
@@ -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);
|
||||
}
|
||||
}
|
||||
|
@@ -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();
|
||||
|
@@ -0,0 +1,8 @@
|
||||
package com.jcraft.jsch;
|
||||
|
||||
final class JavaVersion {
|
||||
|
||||
static int getVersion() {
|
||||
return 8;
|
||||
}
|
||||
}
|
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
@@ -68,7 +68,12 @@ public abstract class KeyExchange{
|
||||
protected byte[] K_S=null;
|
||||
|
||||
public abstract void init(Session session,
|
||||
byte[] V_S, byte[] V_C, byte[] I_S, byte[] I_C) throws Exception;
|
||||
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);
|
||||
@@ -115,43 +122,68 @@ public abstract class KeyExchange{
|
||||
|
||||
loop:
|
||||
while(j<cp.length){
|
||||
while(j<cp.length && cp[j]!=',')j++;
|
||||
if(k==j) return null;
|
||||
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(algorithm.equals(Util.byte2str(sp, m, l-m))){
|
||||
guess[i]=algorithm;
|
||||
break loop;
|
||||
}
|
||||
l++;
|
||||
m=l;
|
||||
}
|
||||
j++;
|
||||
k=j;
|
||||
while(j<cp.length && cp[j]!=',')j++;
|
||||
if(k==j) throw new JSchAlgoNegoFailException(i, Util.byte2str(cp), Util.byte2str(sp));
|
||||
String algorithm=Util.byte2str(cp, k, j-k);
|
||||
int l=0;
|
||||
int m=0;
|
||||
while(l<sp.length){
|
||||
while(l<sp.length && sp[l]!=',')l++;
|
||||
if(m==l) throw new JSchAlgoNegoFailException(i, Util.byte2str(cp), Util.byte2str(sp));
|
||||
if(algorithm.equals(Util.byte2str(sp, m, l-m))){
|
||||
guess[i]=algorithm;
|
||||
break loop;
|
||||
}
|
||||
l++;
|
||||
m=l;
|
||||
}
|
||||
j++;
|
||||
k=j;
|
||||
}
|
||||
if(j==0){
|
||||
guess[i]="";
|
||||
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; }
|
||||
@@ -211,11 +244,13 @@ public abstract class KeyExchange{
|
||||
((K_S[i++]<<8)&0x0000ff00)|((K_S[i++])&0x000000ff);
|
||||
tmp=new byte[j]; System.arraycopy(K_S, i, tmp, 0, j); i+=j;
|
||||
n=tmp;
|
||||
|
||||
|
||||
SignatureRSA sig=null;
|
||||
Buffer buf=new Buffer(sig_of_H);
|
||||
String foo=Util.byte2str(buf.getString());
|
||||
try{
|
||||
Class 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")){
|
||||
@@ -241,7 +276,7 @@ public abstract class KeyExchange{
|
||||
key_alg_name=alg;
|
||||
|
||||
j=((K_S[i++]<<24)&0xff000000)|((K_S[i++]<<16)&0x00ff0000)|
|
||||
((K_S[i++]<<8)&0x0000ff00)|((K_S[i++])&0x000000ff);
|
||||
((K_S[i++]<<8)&0x0000ff00)|((K_S[i++])&0x000000ff);
|
||||
tmp=new byte[j]; System.arraycopy(K_S, i, tmp, 0, j); i+=j;
|
||||
p=tmp;
|
||||
j=((K_S[i++]<<24)&0xff000000)|((K_S[i++]<<16)&0x00ff0000)|
|
||||
@@ -249,7 +284,7 @@ public abstract class KeyExchange{
|
||||
tmp=new byte[j]; System.arraycopy(K_S, i, tmp, 0, j); i+=j;
|
||||
q=tmp;
|
||||
j=((K_S[i++]<<24)&0xff000000)|((K_S[i++]<<16)&0x00ff0000)|
|
||||
((K_S[i++]<<8)&0x0000ff00)|((K_S[i++])&0x000000ff);
|
||||
((K_S[i++]<<8)&0x0000ff00)|((K_S[i++])&0x000000ff);
|
||||
tmp=new byte[j]; System.arraycopy(K_S, i, tmp, 0, j); i+=j;
|
||||
g=tmp;
|
||||
j=((K_S[i++]<<24)&0xff000000)|((K_S[i++]<<16)&0x00ff0000)|
|
||||
@@ -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,10 +349,48 @@ 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");
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -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();
|
||||
@@ -74,19 +77,20 @@ public class KeyPairDSA extends KeyPair{
|
||||
keypairgen=null;
|
||||
}
|
||||
catch(Exception e){
|
||||
//System.err.println("KeyPairDSA: "+e);
|
||||
if(e instanceof Throwable)
|
||||
throw new JSchException(e.toString(), (Throwable)e);
|
||||
throw new JSchException(e.toString());
|
||||
//System.err.println("KeyPairDSA: "+e);
|
||||
throw new JSchException(e.toString(), e);
|
||||
}
|
||||
}
|
||||
|
||||
private static final byte[] begin=Util.str2byte("-----BEGIN DSA PRIVATE KEY-----");
|
||||
private static final byte[] end=Util.str2byte("-----END DSA PRIVATE KEY-----");
|
||||
|
||||
@Override
|
||||
byte[] getBegin(){ return begin; }
|
||||
@Override
|
||||
byte[] getEnd(){ return end; }
|
||||
|
||||
@Override
|
||||
byte[] getPrivateKey(){
|
||||
int content=
|
||||
1+countLength(1) + 1 + // INTEGER
|
||||
@@ -111,23 +115,24 @@ public class KeyPairDSA extends KeyPair{
|
||||
return plain;
|
||||
}
|
||||
|
||||
@Override
|
||||
boolean parse(byte[] plain){
|
||||
try{
|
||||
|
||||
if(vendor==VENDOR_FSECURE){
|
||||
if(plain[0]!=0x30){ // FSecure
|
||||
Buffer buf=new Buffer(plain);
|
||||
buf.getInt();
|
||||
P_array=buf.getMPIntBits();
|
||||
G_array=buf.getMPIntBits();
|
||||
Q_array=buf.getMPIntBits();
|
||||
pub_array=buf.getMPIntBits();
|
||||
prv_array=buf.getMPIntBits();
|
||||
if(plain[0]!=0x30){ // FSecure
|
||||
Buffer buf=new Buffer(plain);
|
||||
buf.getInt();
|
||||
P_array=buf.getMPIntBits();
|
||||
G_array=buf.getMPIntBits();
|
||||
Q_array=buf.getMPIntBits();
|
||||
pub_array=buf.getMPIntBits();
|
||||
prv_array=buf.getMPIntBits();
|
||||
if(P_array!=null)
|
||||
key_size = (new java.math.BigInteger(P_array)).bitLength();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
key_size = (new BigInteger(P_array)).bitLength();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
else if(vendor==VENDOR_PUTTY){
|
||||
Buffer buf=new Buffer(plain);
|
||||
@@ -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());
|
||||
try{
|
||||
Class<? extends SignatureDSA> c=Class.forName(JSch.getConfig("signature.dss")).asSubclass(SignatureDSA.class);
|
||||
SignatureDSA dsa=c.getDeclaredConstructor().newInstance();
|
||||
dsa.init();
|
||||
dsa.setPrvKey(prv_array, P_array, Q_array, G_array);
|
||||
|
||||
@@ -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());
|
||||
try{
|
||||
Class<? extends SignatureDSA> c=Class.forName(JSch.getConfig("signature.dss")).asSubclass(SignatureDSA.class);
|
||||
SignatureDSA dsa=c.getDeclaredConstructor().newInstance();
|
||||
dsa.init();
|
||||
|
||||
if(pub_array == null && P_array == null && getPublicKeyBlob()!=null){
|
||||
@@ -280,7 +319,7 @@ public class KeyPairDSA extends KeyPair{
|
||||
Q_array = buf.getString();
|
||||
G_array = buf.getString();
|
||||
pub_array = buf.getString();
|
||||
}
|
||||
}
|
||||
|
||||
dsa.setPubKey(pub_array, P_array, Q_array, G_array);
|
||||
return dsa;
|
||||
@@ -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);
|
||||
|
@@ -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;
|
||||
}
|
||||
}
|
@@ -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,
|
||||
@@ -84,15 +86,16 @@ public class KeyPairECDSA extends KeyPair{
|
||||
this.s_array = s_array;
|
||||
this.prv_array = prv_array;
|
||||
if(prv_array!=null)
|
||||
key_size = prv_array.length>=64 ? 521 :
|
||||
key_size = prv_array.length>=64 ? 521 :
|
||||
(prv_array.length>=48 ? 384 : 256);
|
||||
}
|
||||
|
||||
@Override
|
||||
void generate(int key_size) throws JSchException{
|
||||
this.key_size=key_size;
|
||||
try{
|
||||
Class 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,20 +105,21 @@ 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);
|
||||
}
|
||||
}
|
||||
|
||||
private static final byte[] begin =
|
||||
private static final byte[] begin =
|
||||
Util.str2byte("-----BEGIN EC PRIVATE KEY-----");
|
||||
private static final byte[] end =
|
||||
Util.str2byte("-----END EC PRIVATE KEY-----");
|
||||
|
||||
@Override
|
||||
byte[] getBegin(){ return begin; }
|
||||
@Override
|
||||
byte[] getEnd(){ return end; }
|
||||
|
||||
@Override
|
||||
byte[] getPrivateKey(){
|
||||
|
||||
byte[] tmp = new byte[1]; tmp[0]=1;
|
||||
@@ -130,7 +134,7 @@ public class KeyPairECDSA extends KeyPair{
|
||||
int bar = ((point.length+1)&0x80)==0 ? 3 : 4;
|
||||
byte[] foo = new byte[point.length+bar];
|
||||
System.arraycopy(point, 0, foo, bar, point.length);
|
||||
foo[0]=0x03; // BITSTRING
|
||||
foo[0]=0x03; // BITSTRING
|
||||
if(bar==3){
|
||||
foo[1]=(byte)(point.length+1);
|
||||
}
|
||||
@@ -160,17 +164,18 @@ public class KeyPairECDSA extends KeyPair{
|
||||
return plain;
|
||||
}
|
||||
|
||||
@Override
|
||||
boolean parse(byte[] plain){
|
||||
try{
|
||||
|
||||
if(vendor==VENDOR_FSECURE){
|
||||
/*
|
||||
if(plain[0]!=0x30){ // FSecure
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
if(plain[0]!=0x30){ // FSecure
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
*/
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
else if(vendor==VENDOR_PUTTY){
|
||||
/*
|
||||
@@ -187,7 +192,43 @@ public class KeyPairECDSA extends KeyPair{
|
||||
|
||||
return true;
|
||||
*/
|
||||
return false;
|
||||
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;
|
||||
@@ -260,7 +301,7 @@ public class KeyPairECDSA extends KeyPair{
|
||||
s_array = tmp[1];
|
||||
|
||||
if(prv_array!=null)
|
||||
key_size = prv_array.length>=64 ? 521 :
|
||||
key_size = prv_array.length>=64 ? 521 :
|
||||
(prv_array.length>=48 ? 384 : 256);
|
||||
}
|
||||
catch(Exception e){
|
||||
@@ -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){
|
||||
@@ -333,7 +385,7 @@ public class KeyPairECDSA extends KeyPair{
|
||||
byte[][] tmp = fromPoint(buf.getString());
|
||||
r_array = tmp[0];
|
||||
s_array = tmp[1];
|
||||
}
|
||||
}
|
||||
ecdsa.setPubKey(r_array, s_array);
|
||||
return ecdsa;
|
||||
}
|
||||
@@ -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);
|
||||
|
@@ -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;
|
||||
}
|
||||
}
|
@@ -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;
|
||||
}
|
||||
}
|
@@ -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);
|
||||
}
|
||||
}
|
@@ -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();
|
||||
}
|
@@ -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;
|
||||
}
|
@@ -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;
|
||||
|
@@ -31,9 +31,9 @@ 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[] pub_array; // e
|
||||
private byte[] prv_array; // d e^-1 mod (p-1)(q-1)
|
||||
|
||||
private byte[] p_array; // prime p
|
||||
@@ -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();
|
||||
@@ -80,19 +81,20 @@ public class KeyPairRSA extends KeyPair{
|
||||
keypairgen=null;
|
||||
}
|
||||
catch(Exception e){
|
||||
//System.err.println("KeyPairRSA: "+e);
|
||||
if(e instanceof Throwable)
|
||||
throw new JSchException(e.toString(), (Throwable)e);
|
||||
throw new JSchException(e.toString());
|
||||
//System.err.println("KeyPairRSA: "+e);
|
||||
throw new JSchException(e.toString(), e);
|
||||
}
|
||||
}
|
||||
|
||||
private static final byte[] begin=Util.str2byte("-----BEGIN RSA PRIVATE KEY-----");
|
||||
private static final byte[] end=Util.str2byte("-----END RSA PRIVATE KEY-----");
|
||||
|
||||
@Override
|
||||
byte[] getBegin(){ return begin; }
|
||||
@Override
|
||||
byte[] getEnd(){ return end; }
|
||||
|
||||
@Override
|
||||
byte[] getPrivateKey(){
|
||||
int content=
|
||||
1+countLength(1) + 1 + // INTEGER
|
||||
@@ -123,6 +125,7 @@ public class KeyPairRSA extends KeyPair{
|
||||
return plain;
|
||||
}
|
||||
|
||||
@Override
|
||||
boolean parse(byte [] plain){
|
||||
|
||||
try{
|
||||
@@ -151,27 +154,49 @@ public class KeyPairRSA extends KeyPair{
|
||||
}
|
||||
|
||||
if(vendor==VENDOR_FSECURE){
|
||||
if(plain[index]!=0x30){ // FSecure
|
||||
Buffer buf=new Buffer(plain);
|
||||
pub_array=buf.getMPIntBits();
|
||||
prv_array=buf.getMPIntBits();
|
||||
n_array=buf.getMPIntBits();
|
||||
byte[] u_array=buf.getMPIntBits();
|
||||
p_array=buf.getMPIntBits();
|
||||
q_array=buf.getMPIntBits();
|
||||
if(plain[index]!=0x30){ // FSecure
|
||||
Buffer buf=new Buffer(plain);
|
||||
pub_array=buf.getMPIntBits();
|
||||
prv_array=buf.getMPIntBits();
|
||||
n_array=buf.getMPIntBits();
|
||||
byte[] u_array=buf.getMPIntBits();
|
||||
p_array=buf.getMPIntBits();
|
||||
q_array=buf.getMPIntBits();
|
||||
if(n_array!=null){
|
||||
key_size = (new java.math.BigInteger(n_array)).bitLength();
|
||||
key_size = (new BigInteger(n_array)).bitLength();
|
||||
}
|
||||
|
||||
getEPArray();
|
||||
getEQArray();
|
||||
getCArray();
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
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){
|
||||
try{
|
||||
Class c=Class.forName((String)jsch.getConfig("signature.rsa"));
|
||||
SignatureRSA rsa=(SignatureRSA)(c.newInstance());
|
||||
return getSignature(data, "ssh-rsa");
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] getSignature(byte[] data, String alg){
|
||||
try{
|
||||
Class<? extends SignatureRSA> c=Class.forName(JSch.getConfig(alg)).asSubclass(SignatureRSA.class);
|
||||
SignatureRSA rsa=c.getDeclaredConstructor().newInstance();
|
||||
rsa.init();
|
||||
rsa.setPrvKey(prv_array, n_array);
|
||||
|
||||
rsa.update(data);
|
||||
byte[] sig = rsa.sign();
|
||||
byte[][] tmp = new byte[2][];
|
||||
tmp[0] = 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(){
|
||||
try{
|
||||
Class c=Class.forName((String)jsch.getConfig("signature.rsa"));
|
||||
SignatureRSA rsa=(SignatureRSA)(c.newInstance());
|
||||
return getVerifier("ssh-rsa");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Signature getVerifier(String alg){
|
||||
try{
|
||||
Class<? extends SignatureRSA> c=Class.forName(JSch.getConfig(alg)).asSubclass(SignatureRSA.class);
|
||||
SignatureRSA rsa=c.getDeclaredConstructor().newInstance();
|
||||
rsa.init();
|
||||
|
||||
if(pub_array == null && n_array == null && getPublicKeyBlob()!=null){
|
||||
@@ -346,7 +387,7 @@ public class KeyPairRSA extends KeyPair{
|
||||
buf.getString();
|
||||
pub_array = buf.getString();
|
||||
n_array = buf.getString();
|
||||
}
|
||||
}
|
||||
|
||||
rsa.setPubKey(pub_array, n_array);
|
||||
return rsa;
|
||||
@@ -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.");
|
||||
@@ -395,22 +437,23 @@ public class KeyPairRSA extends KeyPair{
|
||||
ep_array=(new BigInteger(prv_array)).mod(new BigInteger(p_array).subtract(BigInteger.ONE)).toByteArray();
|
||||
}
|
||||
return ep_array;
|
||||
}
|
||||
}
|
||||
|
||||
private byte[] getEQArray(){
|
||||
if(eq_array==null){
|
||||
eq_array=(new BigInteger(prv_array)).mod(new BigInteger(q_array).subtract(BigInteger.ONE)).toByteArray();
|
||||
}
|
||||
return eq_array;
|
||||
}
|
||||
}
|
||||
|
||||
private byte[] getCArray(){
|
||||
if(c_array==null){
|
||||
c_array=(new BigInteger(q_array)).modInverse(new BigInteger(p_array)).toByteArray();
|
||||
}
|
||||
return c_array;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose(){
|
||||
super.dispose();
|
||||
Util.bzero(prv_array);
|
||||
|
@@ -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){
|
||||
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;
|
||||
@@ -73,15 +79,15 @@ class KnownHosts implements HostKeyRepository{
|
||||
int bufl=0;
|
||||
loop:
|
||||
while(true){
|
||||
bufl=0;
|
||||
bufl=0;
|
||||
while(true){
|
||||
j=fis.read();
|
||||
if(j==-1){
|
||||
if(bufl==0){ break loop; }
|
||||
else{ break; }
|
||||
break;
|
||||
}
|
||||
if(j==0x0d){ continue; }
|
||||
if(j==0x0a){ break; }
|
||||
if(j==0x0d){ continue; }
|
||||
if(j==0x0a){ break; }
|
||||
if(buf.length<=bufl){
|
||||
if(bufl>1024*10) break; // too long...
|
||||
byte[] newbuf=new byte[buf.length*2];
|
||||
@@ -89,38 +95,38 @@ loop:
|
||||
buf=newbuf;
|
||||
}
|
||||
buf[bufl++]=(byte)j;
|
||||
}
|
||||
}
|
||||
|
||||
j=0;
|
||||
j=0;
|
||||
while(j<bufl){
|
||||
i=buf[j];
|
||||
if(i==' '||i=='\t'){ j++; continue; }
|
||||
if(i=='#'){
|
||||
addInvalidLine(Util.byte2str(buf, 0, bufl));
|
||||
continue loop;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if(j>=bufl){
|
||||
addInvalidLine(Util.byte2str(buf, 0, bufl));
|
||||
continue loop;
|
||||
}
|
||||
if(i==' '||i=='\t'){ j++; continue; }
|
||||
if(i=='#'){
|
||||
addInvalidLine(Util.byte2str(buf, 0, bufl));
|
||||
continue loop;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if(j>=bufl){
|
||||
addInvalidLine(Util.byte2str(buf, 0, bufl));
|
||||
continue loop;
|
||||
}
|
||||
|
||||
sb.setLength(0);
|
||||
while(j<bufl){
|
||||
i=buf[j++];
|
||||
if(i==0x20 || i=='\t'){ break; }
|
||||
sb.append((char)i);
|
||||
}
|
||||
host=sb.toString();
|
||||
if(j>=bufl || host.length()==0){
|
||||
addInvalidLine(Util.byte2str(buf, 0, bufl));
|
||||
continue loop;
|
||||
}
|
||||
}
|
||||
host=sb.toString();
|
||||
if(j>=bufl || host.length()==0){
|
||||
addInvalidLine(Util.byte2str(buf, 0, bufl));
|
||||
continue loop;
|
||||
}
|
||||
|
||||
while(j<bufl){
|
||||
i=buf[j];
|
||||
if(i==' '||i=='\t'){ j++; continue; }
|
||||
if(i==' '||i=='\t'){ j++; continue; }
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -148,25 +154,25 @@ loop:
|
||||
}
|
||||
|
||||
sb.setLength(0);
|
||||
type=-1;
|
||||
type=-1;
|
||||
while(j<bufl){
|
||||
i=buf[j++];
|
||||
if(i==0x20 || i=='\t'){ break; }
|
||||
sb.append((char)i);
|
||||
}
|
||||
String tmp = sb.toString();
|
||||
if(HostKey.name2type(tmp)!=HostKey.UNKNOWN){
|
||||
type=HostKey.name2type(tmp);
|
||||
}
|
||||
else { j=bufl; }
|
||||
if(j>=bufl){
|
||||
addInvalidLine(Util.byte2str(buf, 0, bufl));
|
||||
continue loop;
|
||||
}
|
||||
}
|
||||
String tmp = sb.toString();
|
||||
if(HostKey.name2type(tmp)!=HostKey.UNKNOWN){
|
||||
type=HostKey.name2type(tmp);
|
||||
}
|
||||
else { j=bufl; }
|
||||
if(j>=bufl){
|
||||
addInvalidLine(Util.byte2str(buf, 0, bufl));
|
||||
continue loop;
|
||||
}
|
||||
|
||||
while(j<bufl){
|
||||
i=buf[j];
|
||||
if(i==' '||i=='\t'){ j++; continue; }
|
||||
if(i==' '||i=='\t'){ j++; continue; }
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -177,16 +183,16 @@ loop:
|
||||
if(i==0x0a){ break; }
|
||||
if(i==0x20 || i=='\t'){ break; }
|
||||
sb.append((char)i);
|
||||
}
|
||||
key=sb.toString();
|
||||
if(key.length()==0){
|
||||
addInvalidLine(Util.byte2str(buf, 0, bufl));
|
||||
continue loop;
|
||||
}
|
||||
}
|
||||
key=sb.toString();
|
||||
if(key.length()==0){
|
||||
addInvalidLine(Util.byte2str(buf, 0, bufl));
|
||||
continue loop;
|
||||
}
|
||||
|
||||
while(j<bufl){
|
||||
i=buf[j];
|
||||
if(i==' '||i=='\t'){ j++; continue; }
|
||||
if(i==' '||i=='\t'){ j++; continue; }
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -212,30 +218,28 @@ loop:
|
||||
comment=sb.toString();
|
||||
}
|
||||
|
||||
//System.err.println(host);
|
||||
//System.err.println("|"+key+"|");
|
||||
//System.err.println(host);
|
||||
//System.err.println("|"+key+"|");
|
||||
|
||||
HostKey hk = null;
|
||||
HostKey hk = null;
|
||||
hk = new HashedHostKey(marker, host, type,
|
||||
Util.fromBase64(Util.str2byte(key), 0,
|
||||
key.length()), comment);
|
||||
pool.addElement(hk);
|
||||
pool.addElement(hk);
|
||||
}
|
||||
if(error){
|
||||
throw new JSchException("KnownHosts: invalid format");
|
||||
throw new JSchException("KnownHosts: invalid format");
|
||||
}
|
||||
}
|
||||
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 (JSchException)e;
|
||||
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,20 +262,19 @@ 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;
|
||||
}
|
||||
result=CHANGED;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -284,26 +289,27 @@ 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; }
|
||||
if(hk.host.equals(host)){
|
||||
hk.key=key;
|
||||
return;
|
||||
}
|
||||
else{
|
||||
hk.host=deleteSubString(hk.host, host);
|
||||
break;
|
||||
}
|
||||
if(Util.array_equals(hk.key, key)){ return; }
|
||||
if(hk.host.equals(host)){
|
||||
hk.key=key;
|
||||
return;
|
||||
}
|
||||
else{
|
||||
hk.host=deleteSubString(hk.host, host);
|
||||
break;
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
@@ -313,61 +319,71 @@ loop:
|
||||
|
||||
pool.addElement(hk);
|
||||
|
||||
String bar=getKnownHostsRepositoryID();
|
||||
if(bar!=null){
|
||||
boolean foo=true;
|
||||
File goo=new File(Util.checkTilde(bar));
|
||||
if(!goo.exists()){
|
||||
foo=false;
|
||||
if(userinfo!=null){
|
||||
foo=userinfo.promptYesNo(bar+" does not exist.\n"+
|
||||
syncKnownHostsFile(userinfo);
|
||||
}
|
||||
|
||||
void syncKnownHostsFile(UserInfo userinfo) {
|
||||
String khFilename = getKnownHostsRepositoryID();
|
||||
if (khFilename == null) {
|
||||
return;
|
||||
}
|
||||
boolean doSync=true;
|
||||
File goo=new File(Util.checkTilde(khFilename ));
|
||||
if(!goo.exists()){
|
||||
doSync = false;
|
||||
if (userinfo!=null) {
|
||||
doSync = userinfo.promptYesNo(khFilename +" does not exist.\n"+
|
||||
"Are you sure you want to create it?"
|
||||
);
|
||||
goo=goo.getParentFile();
|
||||
if(doSync && goo!=null && !goo.exists()){
|
||||
doSync=userinfo.promptYesNo("The parent directory "+goo+" does not exist.\n"+
|
||||
"Are you sure you want to create it?"
|
||||
);
|
||||
goo=goo.getParentFile();
|
||||
if(foo && goo!=null && !goo.exists()){
|
||||
foo=userinfo.promptYesNo("The parent directory "+goo+" does not exist.\n"+
|
||||
"Are you sure you want to create it?"
|
||||
);
|
||||
if(foo){
|
||||
if(!goo.mkdirs()){
|
||||
userinfo.showMessage(goo+" has not been created.");
|
||||
foo=false;
|
||||
}
|
||||
else{
|
||||
userinfo.showMessage(goo+" has been succesfully created.\nPlease check its access permission.");
|
||||
}
|
||||
if(doSync){
|
||||
if(!goo.mkdirs()){
|
||||
userinfo.showMessage(goo+" has not been created.");
|
||||
doSync=false;
|
||||
}
|
||||
else{
|
||||
userinfo.showMessage(goo+" has been succesfully created.\nPlease check its access permission.");
|
||||
}
|
||||
}
|
||||
if(goo==null)foo=false;
|
||||
}
|
||||
if(goo==null)doSync=false;
|
||||
}
|
||||
if(foo){
|
||||
try{
|
||||
sync(bar);
|
||||
}
|
||||
catch(Exception e){ System.err.println("sync known_hosts: "+e); }
|
||||
}
|
||||
}
|
||||
if(!doSync){
|
||||
return;
|
||||
}
|
||||
try{
|
||||
sync(khFilename);
|
||||
}
|
||||
catch(Exception e) {
|
||||
jsch.getInstanceLogger().log(Logger.ERROR, "unable to sync known host file " + goo.getPath(), e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public HostKey[] getHostKey(){
|
||||
return getHostKey(null, (String)null);
|
||||
}
|
||||
@Override
|
||||
public HostKey[] getHostKey(String host, String type){
|
||||
synchronized(pool){
|
||||
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);
|
||||
if(hk.type==HostKey.UNKNOWN) continue;
|
||||
if(host==null ||
|
||||
(hk.isMatched(host) &&
|
||||
(type==null || hk.getType().equals(type)))){
|
||||
HostKey hk=pool.elementAt(i);
|
||||
if(hk.type==HostKey.UNKNOWN) continue;
|
||||
if(host==null ||
|
||||
(hk.isMatched(host) &&
|
||||
(type==null || hk.getType().equals(type)))){
|
||||
v.add(hk);
|
||||
}
|
||||
}
|
||||
}
|
||||
HostKey[] foo = new HostKey[v.size()];
|
||||
for(int i=0; i<v.size(); i++){
|
||||
foo[i] = (HostKey)v.get(i);
|
||||
foo[i] = v.get(i);
|
||||
}
|
||||
if(host != null && host.startsWith("[") && host.indexOf("]:")>1){
|
||||
HostKey[] tmp =
|
||||
@@ -382,28 +398,31 @@ 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)))))){
|
||||
(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);
|
||||
}
|
||||
sync=true;
|
||||
sync=true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -412,58 +431,63 @@ 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));
|
||||
dump(fos);
|
||||
fos.close();
|
||||
try (FileOutputStream fos = new FileOutputStream(Util.checkTilde(foo))) {
|
||||
dump(fos);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
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;
|
||||
}
|
||||
if(marker.length()!=0){
|
||||
out.write(Util.str2byte(marker));
|
||||
out.write(space);
|
||||
}
|
||||
out.write(Util.str2byte(host));
|
||||
out.write(space);
|
||||
out.write(Util.str2byte(type));
|
||||
out.write(space);
|
||||
out.write(Util.str2byte(hk.getKey()));
|
||||
if(comment!=null){
|
||||
out.write(space);
|
||||
out.write(Util.str2byte(comment));
|
||||
}
|
||||
out.write(cr);
|
||||
hk=pool.elementAt(i);
|
||||
dumpHostKey(out, hk);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(Exception e){
|
||||
System.err.println(e);
|
||||
jsch.getInstanceLogger().log(Logger.ERROR, "unable to dump known hosts", e);
|
||||
}
|
||||
}
|
||||
|
||||
private String deleteSubString(String hosts, String host){
|
||||
void dumpHostKey(OutputStream out, HostKey hk) throws IOException {
|
||||
String marker=hk.getMarker();
|
||||
String host=hk.getHost();
|
||||
String type=hk.getType();
|
||||
String comment = hk.getComment();
|
||||
if (type.equals("UNKNOWN")) {
|
||||
out.write(Util.str2byte(host));
|
||||
out.write(lf);
|
||||
return;
|
||||
}
|
||||
if (marker.length() != 0) {
|
||||
out.write(Util.str2byte(marker));
|
||||
out.write(space);
|
||||
}
|
||||
out.write(Util.str2byte(host));
|
||||
out.write(space);
|
||||
out.write(Util.str2byte(type));
|
||||
out.write(space);
|
||||
out.write(Util.str2byte(hk.getKey()));
|
||||
|
||||
if (comment != null) {
|
||||
out.write(space);
|
||||
out.write(Util.str2byte(comment));
|
||||
}
|
||||
out.write(lf);
|
||||
}
|
||||
|
||||
String deleteSubString(String hosts, String host){
|
||||
int i=0;
|
||||
int hostlen=host.length();
|
||||
int hostslen=hosts.length();
|
||||
@@ -472,7 +496,7 @@ loop:
|
||||
j=hosts.indexOf(',', i);
|
||||
if(j==-1) break;
|
||||
if(!host.equals(hosts.substring(i, j))){
|
||||
i=j+1;
|
||||
i=j+1;
|
||||
continue;
|
||||
}
|
||||
return hosts.substring(0, i)+hosts.substring(j+1);
|
||||
@@ -483,18 +507,24 @@ loop:
|
||||
return hosts;
|
||||
}
|
||||
|
||||
private MAC getHMACSHA1(){
|
||||
if(hmacsha1==null){
|
||||
try{
|
||||
Class c=Class.forName(jsch.getConfig("hmac-sha1"));
|
||||
hmacsha1=(MAC)(c.newInstance());
|
||||
}
|
||||
catch(Exception e){
|
||||
System.err.println("hmacsha1: "+e);
|
||||
}
|
||||
MAC getHMACSHA1() throws IllegalArgumentException {
|
||||
if (hmacsha1 == null){
|
||||
hmacsha1 = createHMAC(JSch.getConfig("hmac-sha1"));
|
||||
}
|
||||
|
||||
return hmacsha1;
|
||||
}
|
||||
|
||||
MAC createHMAC(String hmacClassname) throws IllegalArgumentException {
|
||||
try{
|
||||
Class<? extends MAC> c=Class.forName(hmacClassname).asSubclass(MAC.class);
|
||||
return c.getDeclaredConstructor().newInstance();
|
||||
}
|
||||
catch(Exception e){
|
||||
jsch.getInstanceLogger().log(Logger.ERROR, "unable to instantiate HMAC-class " + hmacClassname, e);
|
||||
throw new IllegalArgumentException("instantiation of " + hmacClassname + " lead to an error", e);
|
||||
}
|
||||
}
|
||||
|
||||
HostKey createHashedHostKey(String host, byte[]key) throws JSchException {
|
||||
HashedHostKey hhk=new HashedHostKey(host, key);
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
@@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -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;
|
||||
@@ -40,6 +43,20 @@ public interface Logger{
|
||||
public boolean isEnabled(int level);
|
||||
|
||||
public void log(int level, String message);
|
||||
|
||||
public default void log(int level, String message, Throwable cause) {
|
||||
if (!isEnabled(level)) {
|
||||
return;
|
||||
}
|
||||
if (cause != null) {
|
||||
StringWriter sw = new StringWriter();
|
||||
try (PrintWriter pw = new PrintWriter(sw, true)) {
|
||||
cause.printStackTrace(pw);
|
||||
}
|
||||
message += System.lineSeparator() + sw.toString();
|
||||
}
|
||||
log(level, message);
|
||||
}
|
||||
|
||||
/*
|
||||
public final Logger SIMPLE_LOGGER=new Logger(){
|
||||
|
@@ -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;}
|
||||
}
|
||||
|
@@ -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>
|
||||
@@ -60,7 +68,7 @@ import java.util.Vector;
|
||||
* <li>CompressionLevel</li>
|
||||
* <li>ForwardAgent</li>
|
||||
* <li>RequestTTY</li>
|
||||
* <li>ServerAliveInterval</li>
|
||||
* <li>ServerAliveInterval</li>
|
||||
* <li>LocalForward</li>
|
||||
* <li>RemoteForward</li>
|
||||
* <li>ClearAllForwardings</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);
|
||||
}
|
||||
finally {
|
||||
r.close();
|
||||
try(Reader r = new StringReader(conf)) {
|
||||
try(BufferedReader br = new BufferedReader(r)) {
|
||||
return new OpenSSHConfig(br);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
@@ -245,13 +278,16 @@ public class OpenSSHConfig implements ConfigRepository {
|
||||
}
|
||||
}
|
||||
}
|
||||
String[] result = new String[value.size()];
|
||||
String[] result = new String[value.size()];
|
||||
value.toArray(result);
|
||||
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); }
|
||||
}
|
||||
}
|
||||
|
@@ -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);
|
||||
@@ -91,8 +97,8 @@ System.err.println("");
|
||||
// System.err.println("buffer.buffer.length="+buffer.buffer.length+" s="+(s));
|
||||
|
||||
System.arraycopy(buffer.buffer,
|
||||
len+5+9,
|
||||
buffer.buffer, s, buffer.index-5-9-len);
|
||||
len+5+9,
|
||||
buffer.buffer, s, buffer.index-5-9-len);
|
||||
|
||||
buffer.index=10;
|
||||
buffer.putInt(len);
|
||||
@@ -101,8 +107,8 @@ System.err.println("");
|
||||
}
|
||||
void unshift(byte command, int recipient, int s, int len){
|
||||
System.arraycopy(buffer.buffer,
|
||||
s,
|
||||
buffer.buffer, 5+9, len);
|
||||
s,
|
||||
buffer.buffer, 5+9, len);
|
||||
buffer.buffer[5]=command;
|
||||
buffer.index=6;
|
||||
buffer.putInt(recipient);
|
||||
|
@@ -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,20 +61,46 @@ 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));
|
||||
if(p.session==session){
|
||||
foo.addElement(p.lport+":"+p.host+":"+p.rport);
|
||||
}
|
||||
PortWatcher p=pool.elementAt(i);
|
||||
if(p.session==session){
|
||||
foo.addElement(p.lport+":"+p.host+":"+p.rport);
|
||||
}
|
||||
}
|
||||
}
|
||||
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,13 +114,13 @@ class PortWatcher implements Runnable{
|
||||
}
|
||||
synchronized(pool){
|
||||
for(int i=0; i<pool.size(); i++){
|
||||
PortWatcher p=(PortWatcher)(pool.elementAt(i));
|
||||
if(p.session==session && p.lport==lport){
|
||||
if(/*p.boundaddress.isAnyLocalAddress() ||*/
|
||||
PortWatcher p=pool.elementAt(i);
|
||||
if(p.session==session && p.lport==lport){
|
||||
if(/*p.boundaddress.isAnyLocalAddress() ||*/
|
||||
(anyLocalAddress!=null && p.boundaddress.equals(anyLocalAddress)) ||
|
||||
p.boundaddress.equals(addr))
|
||||
return p;
|
||||
}
|
||||
p.boundaddress.equals(addr))
|
||||
return p;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -125,66 +157,73 @@ 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));
|
||||
if(p.session==session) {
|
||||
p.delete();
|
||||
foo[count++]=p;
|
||||
}
|
||||
PortWatcher p=pool.elementAt(i);
|
||||
if(p.session==session) {
|
||||
p.delete();
|
||||
foo[count++]=p;
|
||||
}
|
||||
}
|
||||
for(int i=0; i<count; i++){
|
||||
PortWatcher p=foo[i];
|
||||
pool.removeElement(p);
|
||||
PortWatcher p=foo[i];
|
||||
pool.removeElement(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
PortWatcher(Session session,
|
||||
String address, int lport,
|
||||
String host, int rport,
|
||||
PortWatcher(Session session,
|
||||
String address, int lport,
|
||||
String host, int rport,
|
||||
ServerSocketFactory factory) throws JSchException{
|
||||
this.session=session;
|
||||
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);
|
||||
socket.setTcpNoDelay(true);
|
||||
InputStream in=socket.getInputStream();
|
||||
OutputStream out=socket.getOutputStream();
|
||||
ChannelDirectTCPIP channel=new ChannelDirectTCPIP();
|
||||
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.connect(connectTimeout);
|
||||
if(channel.exitstatus!=-1){
|
||||
}
|
||||
if(socketPath!=null && socketPath.length()>0){
|
||||
ChannelDirectStreamLocal channel = new ChannelDirectStreamLocal();
|
||||
channel.setSession(session);
|
||||
channel.init();
|
||||
channel.setInputStream(in);
|
||||
channel.setOutputStream(out);
|
||||
session.addChannel(channel);
|
||||
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){
|
||||
@@ -195,7 +234,7 @@ class PortWatcher implements Runnable{
|
||||
|
||||
void delete(){
|
||||
thread=null;
|
||||
try{
|
||||
try{
|
||||
if(ss!=null)ss.close();
|
||||
ss=null;
|
||||
}
|
||||
|
@@ -48,8 +48,8 @@ public class ProxyHTTP implements Proxy{
|
||||
String host=proxy_host;
|
||||
if(proxy_host.indexOf(':')!=-1){
|
||||
try{
|
||||
host=proxy_host.substring(0, proxy_host.indexOf(':'));
|
||||
port=Integer.parseInt(proxy_host.substring(proxy_host.indexOf(':')+1));
|
||||
host=proxy_host.substring(0, proxy_host.indexOf(':'));
|
||||
port=Integer.parseInt(proxy_host.substring(proxy_host.indexOf(':')+1));
|
||||
}
|
||||
catch(Exception e){
|
||||
}
|
||||
@@ -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){
|
||||
@@ -85,11 +86,11 @@ public class ProxyHTTP implements Proxy{
|
||||
out.write(Util.str2byte("CONNECT "+host+":"+port+" HTTP/1.0\r\n"));
|
||||
|
||||
if(user!=null && passwd!=null){
|
||||
byte[] code=Util.str2byte(user+":"+passwd);
|
||||
code=Util.toBase64(code, 0, code.length);
|
||||
out.write(Util.str2byte("Proxy-Authorization: Basic "));
|
||||
out.write(code);
|
||||
out.write(Util.str2byte("\r\n"));
|
||||
byte[] code=Util.str2byte(user+":"+passwd);
|
||||
code=Util.toBase64(code, 0, code.length, true);
|
||||
out.write(Util.str2byte("Proxy-Authorization: Basic "));
|
||||
out.write(code);
|
||||
out.write(Util.str2byte("\r\n"));
|
||||
}
|
||||
|
||||
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();
|
||||
|
@@ -53,8 +53,8 @@ public class ProxySOCKS4 implements Proxy{
|
||||
String host=proxy_host;
|
||||
if(proxy_host.indexOf(':')!=-1){
|
||||
try{
|
||||
host=proxy_host.substring(0, proxy_host.indexOf(':'));
|
||||
port=Integer.parseInt(proxy_host.substring(proxy_host.indexOf(':')+1));
|
||||
host=proxy_host.substring(0, proxy_host.indexOf(':'));
|
||||
port=Integer.parseInt(proxy_host.substring(proxy_host.indexOf(':')+1));
|
||||
}
|
||||
catch(Exception e){
|
||||
}
|
||||
@@ -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){
|
||||
@@ -175,8 +176,8 @@ public class ProxySOCKS4 implements Proxy{
|
||||
}
|
||||
if(buf[1]!=90){
|
||||
try{ socket.close(); }
|
||||
catch(Exception eee){
|
||||
}
|
||||
catch(Exception eee){
|
||||
}
|
||||
String message="ProxySOCKS4: server returns CD "+buf[1];
|
||||
throw new JSchException(message);
|
||||
}
|
||||
@@ -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();
|
||||
|
@@ -53,8 +53,8 @@ public class ProxySOCKS5 implements Proxy{
|
||||
String host=proxy_host;
|
||||
if(proxy_host.indexOf(':')!=-1){
|
||||
try{
|
||||
host=proxy_host.substring(0, proxy_host.indexOf(':'));
|
||||
port=Integer.parseInt(proxy_host.substring(proxy_host.indexOf(':')+1));
|
||||
host=proxy_host.substring(0, proxy_host.indexOf(':'));
|
||||
port=Integer.parseInt(proxy_host.substring(proxy_host.indexOf(':')+1));
|
||||
}
|
||||
catch(Exception e){
|
||||
}
|
||||
@@ -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){
|
||||
@@ -163,11 +164,11 @@ public class ProxySOCKS5 implements Proxy{
|
||||
index=0;
|
||||
buf[index++]=1;
|
||||
buf[index++]=(byte)(user.length());
|
||||
System.arraycopy(Util.str2byte(user), 0, buf, index, user.length());
|
||||
index+=user.length();
|
||||
System.arraycopy(Util.str2byte(user), 0, buf, index, user.length());
|
||||
index+=user.length();
|
||||
buf[index++]=(byte)(passwd.length());
|
||||
System.arraycopy(Util.str2byte(passwd), 0, buf, index, passwd.length());
|
||||
index+=passwd.length();
|
||||
System.arraycopy(Util.str2byte(passwd), 0, buf, index, passwd.length());
|
||||
index+=passwd.length();
|
||||
|
||||
out.write(buf, 0, index);
|
||||
|
||||
@@ -195,8 +196,8 @@ public class ProxySOCKS5 implements Proxy{
|
||||
|
||||
if(!check){
|
||||
try{ socket.close(); }
|
||||
catch(Exception eee){
|
||||
}
|
||||
catch(Exception eee){
|
||||
}
|
||||
throw new JSchException("fail in SOCKS5 proxy");
|
||||
}
|
||||
|
||||
@@ -282,8 +283,8 @@ public class ProxySOCKS5 implements Proxy{
|
||||
|
||||
if(buf[1]!=0){
|
||||
try{ socket.close(); }
|
||||
catch(Exception eee){
|
||||
}
|
||||
catch(Exception eee){
|
||||
}
|
||||
throw new JSchException("ProxySOCKS5: server returns "+buf[1]);
|
||||
}
|
||||
|
||||
@@ -291,13 +292,13 @@ public class ProxySOCKS5 implements Proxy{
|
||||
case 1:
|
||||
//in.read(buf, 0, 6);
|
||||
fill(in, buf, 6);
|
||||
break;
|
||||
break;
|
||||
case 3:
|
||||
//in.read(buf, 0, 1);
|
||||
fill(in, buf, 1);
|
||||
//in.read(buf, 0, buf[0]+2);
|
||||
fill(in, buf, (buf[0]&0xff)+2);
|
||||
break;
|
||||
break;
|
||||
case 4:
|
||||
//in.read(buf, 0, 18);
|
||||
fill(in, buf, 18);
|
||||
@@ -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();
|
||||
|
@@ -51,9 +51,9 @@ abstract class Request{
|
||||
long start=System.currentTimeMillis();
|
||||
long timeout=channel.connectTimeout;
|
||||
while(channel.isConnected() && channel.reply==-1){
|
||||
try{Thread.sleep(10);}
|
||||
catch(Exception ee){
|
||||
}
|
||||
try{Thread.sleep(10);}
|
||||
catch(Exception ee){
|
||||
}
|
||||
if(timeout>0L &&
|
||||
(System.currentTimeMillis()-start)>timeout){
|
||||
channel.reply=0;
|
||||
@@ -62,7 +62,7 @@ abstract class Request{
|
||||
}
|
||||
|
||||
if(channel.reply==0){
|
||||
throw new JSchException("failed to send channel request");
|
||||
throw new JSchException("failed to send channel request");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -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);
|
||||
|
||||
|
@@ -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);
|
||||
|
@@ -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);
|
||||
|
||||
|
@@ -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);
|
||||
|
||||
|
@@ -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);
|
||||
|
||||
|
@@ -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);
|
||||
|
||||
|
@@ -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);
|
||||
|
||||
|
@@ -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);
|
||||
|
||||
|
@@ -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);
|
||||
|
||||
|
@@ -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);
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -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');
|
||||
@@ -145,7 +145,7 @@ public class SftpATTRS {
|
||||
}
|
||||
|
||||
static SftpATTRS getATTR(Buffer buf){
|
||||
SftpATTRS attr=new SftpATTRS();
|
||||
SftpATTRS attr=new SftpATTRS();
|
||||
attr.flags=buf.getInt();
|
||||
if((attr.flags&SSH_FILEXFER_ATTR_SIZE)!=0){ attr.size=buf.getLong(); }
|
||||
if((attr.flags&SSH_FILEXFER_ATTR_UIDGID)!=0){
|
||||
@@ -163,11 +163,11 @@ public class SftpATTRS {
|
||||
if((attr.flags&SSH_FILEXFER_ATTR_EXTENDED)!=0){
|
||||
int count=buf.getInt();
|
||||
if(count>0){
|
||||
attr.extended=new String[count*2];
|
||||
for(int i=0; i<count; i++){
|
||||
attr.extended[i*2]=Util.byte2str(buf.getString());
|
||||
attr.extended[i*2+1]=Util.byte2str(buf.getString());
|
||||
}
|
||||
attr.extended=new String[count*2];
|
||||
for(int i=0; i<count; i++){
|
||||
attr.extended[i*2]=Util.byte2str(buf.getString());
|
||||
attr.extended[i*2+1]=Util.byte2str(buf.getString());
|
||||
}
|
||||
}
|
||||
}
|
||||
return attr;
|
||||
@@ -184,10 +184,10 @@ public class SftpATTRS {
|
||||
len+=4;
|
||||
int count=extended.length/2;
|
||||
if(count>0){
|
||||
for(int i=0; i<count; i++){
|
||||
len+=4; len+=extended[i*2].length();
|
||||
len+=4; len+=extended[i*2+1].length();
|
||||
}
|
||||
for(int i=0; i<count; i++){
|
||||
len+=4; len+=extended[i*2].length();
|
||||
len+=4; len+=extended[i*2+1].length();
|
||||
}
|
||||
}
|
||||
}
|
||||
return len;
|
||||
@@ -207,10 +207,10 @@ public class SftpATTRS {
|
||||
if((flags&SSH_FILEXFER_ATTR_EXTENDED)!=0){
|
||||
int count=extended.length/2;
|
||||
if(count>0){
|
||||
for(int i=0; i<count; i++){
|
||||
buf.putString(Util.str2byte(extended[i*2]));
|
||||
buf.putString(Util.str2byte(extended[i*2+1]));
|
||||
}
|
||||
for(int i=0; i<count; i++){
|
||||
buf.putString(Util.str2byte(extended[i*2]));
|
||||
buf.putString(Util.str2byte(extended[i*2+1]));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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());
|
||||
}
|
||||
|
@@ -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;
|
||||
}
|
||||
}
|
||||
|
@@ -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;
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user