mirror of
https://github.com/hierynomus/sshj.git
synced 2025-12-06 07:10:53 +03:00
Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
80b164a299 | ||
|
|
75418f33b7 | ||
|
|
732de2b605 | ||
|
|
4fb56b868f | ||
|
|
a877ec1448 | ||
|
|
b44631ea97 | ||
|
|
a50962ba2f | ||
|
|
e8215e4af2 | ||
|
|
3c2bda3196 | ||
|
|
b13e22084b |
2
NOTICE
2
NOTICE
@@ -1,5 +1,5 @@
|
||||
sshj - SSHv2 library for Java
|
||||
Copyright 2010-2011 sshj contributors
|
||||
Copyright 2010-2012 sshj contributors
|
||||
|
||||
This product includes code derived from software developed at
|
||||
The Apache Software Foundation (http://www.apache.org/):
|
||||
|
||||
2
pom.xml
2
pom.xml
@@ -6,7 +6,7 @@
|
||||
<groupId>net.schmizz</groupId>
|
||||
<artifactId>sshj</artifactId>
|
||||
<packaging>bundle</packaging>
|
||||
<version>0.8.0</version>
|
||||
<version>0.8.1</version>
|
||||
|
||||
<name>sshj</name>
|
||||
<description>SSHv2 library for Java</description>
|
||||
|
||||
@@ -96,7 +96,7 @@ public class DefaultConfig
|
||||
|
||||
private final Logger log = LoggerFactory.getLogger(getClass());
|
||||
|
||||
private static final String VERSION = "SSHJ_0_8";
|
||||
private static final String VERSION = "SSHJ_0_8_1_SNAPSHOT";
|
||||
|
||||
public DefaultConfig() {
|
||||
setVersion(VERSION);
|
||||
|
||||
@@ -683,7 +683,7 @@ public class SSHClient
|
||||
|
||||
final long start = System.currentTimeMillis();
|
||||
trans.doKex();
|
||||
log.info("Key exchange took {} seconds", (System.currentTimeMillis() - start) / 1000.0);
|
||||
log.debug("Key exchange took {} seconds", (System.currentTimeMillis() - start) / 1000.0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -62,11 +62,11 @@ public class SecurityUtils {
|
||||
public void run()
|
||||
throws Exception {
|
||||
if (java.security.Security.getProvider(BOUNCY_CASTLE) == null) {
|
||||
LOG.info("Trying to register BouncyCastle as a JCE provider");
|
||||
LOG.debug("Trying to register BouncyCastle as a JCE provider");
|
||||
java.security.Security.addProvider(new BouncyCastleProvider());
|
||||
MessageDigest.getInstance("MD5", BOUNCY_CASTLE);
|
||||
KeyAgreement.getInstance("DH", BOUNCY_CASTLE);
|
||||
LOG.info("Registration succeeded");
|
||||
LOG.info("BouncyCastle registration succeeded");
|
||||
} else
|
||||
LOG.info("BouncyCastle already registered as a JCE provider");
|
||||
securityProvider = BOUNCY_CASTLE;
|
||||
|
||||
@@ -136,7 +136,7 @@ public class StreamCopier {
|
||||
|
||||
final double timeSeconds = (System.currentTimeMillis() - startTime) / 1000.0;
|
||||
final double sizeKiB = count / 1024.0;
|
||||
log.info("{} KiB transferred in {} seconds ({} KiB/s)", new Object[] { sizeKiB, timeSeconds, (sizeKiB / timeSeconds) });
|
||||
log.debug("{} KiB transferred in {} seconds ({} KiB/s)", new Object[] { sizeKiB, timeSeconds, (sizeKiB / timeSeconds) });
|
||||
|
||||
if (length != -1 && read == -1)
|
||||
throw new IOException("Encountered EOF, could not transfer " + length + " bytes");
|
||||
|
||||
@@ -65,7 +65,7 @@ public class ConnectionImpl
|
||||
|
||||
@Override
|
||||
public void attach(Channel chan) {
|
||||
log.info("Attaching `{}` channel (#{})", chan.getType(), chan.getID());
|
||||
log.debug("Attaching `{}` channel (#{})", chan.getType(), chan.getID());
|
||||
channels.put(chan.getID(), chan);
|
||||
}
|
||||
|
||||
@@ -81,7 +81,7 @@ public class ConnectionImpl
|
||||
|
||||
@Override
|
||||
public void forget(Channel chan) {
|
||||
log.info("Forgetting `{}` channel (#{})", chan.getType(), chan.getID());
|
||||
log.debug("Forgetting `{}` channel (#{})", chan.getType(), chan.getID());
|
||||
channels.remove(chan.getID());
|
||||
synchronized (internalSynchronizer) {
|
||||
if (channels.isEmpty())
|
||||
@@ -91,13 +91,13 @@ public class ConnectionImpl
|
||||
|
||||
@Override
|
||||
public void forget(ForwardedChannelOpener opener) {
|
||||
log.info("Forgetting opener for `{}` channels: {}", opener.getChannelType(), opener);
|
||||
log.debug("Forgetting opener for `{}` channels: {}", opener.getChannelType(), opener);
|
||||
openers.remove(opener.getChannelType());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void attach(ForwardedChannelOpener opener) {
|
||||
log.info("Attaching opener for `{}` channels: {}", opener.getChannelType(), opener);
|
||||
log.debug("Attaching opener for `{}` channels: {}", opener.getChannelType(), opener);
|
||||
openers.put(opener.getChannelType(), opener);
|
||||
}
|
||||
|
||||
@@ -187,7 +187,7 @@ public class ConnectionImpl
|
||||
byte[] specifics)
|
||||
throws TransportException {
|
||||
synchronized (globalReqPromises) {
|
||||
log.info("Making global request for `{}`", name);
|
||||
log.debug("Making global request for `{}`", name);
|
||||
trans.write(new SSHPacket(Message.GLOBAL_REQUEST).putString(name)
|
||||
.putBoolean(wantReply)
|
||||
.putRawBytes(specifics));
|
||||
|
||||
@@ -81,11 +81,11 @@ public abstract class AbstractChannel
|
||||
private final Queue<Event<ConnectionException>> chanReqResponseEvents = new LinkedList<Event<ConnectionException>>();
|
||||
|
||||
/* The lock used by to create the open & close events */
|
||||
private final ReentrantLock lock = new ReentrantLock();
|
||||
private final ReentrantLock openCloseLock = new ReentrantLock();
|
||||
/** Channel open event */
|
||||
protected final Event<ConnectionException> open;
|
||||
protected final Event<ConnectionException> openEvent;
|
||||
/** Channel close event */
|
||||
protected final Event<ConnectionException> close;
|
||||
protected final Event<ConnectionException> closeEvent;
|
||||
|
||||
/* Access to these fields should be synchronized using this object */
|
||||
private boolean eofSent;
|
||||
@@ -114,15 +114,15 @@ public abstract class AbstractChannel
|
||||
lwin = new Window.Local(conn.getWindowSize(), conn.getMaxPacketSize());
|
||||
in = new ChannelInputStream(this, trans, lwin);
|
||||
|
||||
open = new Event<ConnectionException>("chan#" + id + " / " + "open", ConnectionException.chainer, lock);
|
||||
close = new Event<ConnectionException>("chan#" + id + " / " + "close", ConnectionException.chainer, lock);
|
||||
openEvent = new Event<ConnectionException>("chan#" + id + " / " + "open", ConnectionException.chainer, openCloseLock);
|
||||
closeEvent = new Event<ConnectionException>("chan#" + id + " / " + "close", ConnectionException.chainer, openCloseLock);
|
||||
}
|
||||
|
||||
protected void init(int recipient, long remoteWinSize, long remoteMaxPacketSize) {
|
||||
this.recipient = recipient;
|
||||
rwin = new Window.Remote(remoteWinSize, (int) Math.min(remoteMaxPacketSize, REMOTE_MAX_PACKET_SIZE_CEILING));
|
||||
out = new ChannelOutputStream(this, trans, rwin);
|
||||
log.info("Initialized - {}", this);
|
||||
log.debug("Initialized - {}", this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -220,7 +220,7 @@ public abstract class AbstractChannel
|
||||
|
||||
private void gotClose()
|
||||
throws TransportException {
|
||||
log.info("Got close");
|
||||
log.debug("Got close");
|
||||
try {
|
||||
closeAllStreams();
|
||||
sendClose();
|
||||
@@ -238,7 +238,7 @@ public abstract class AbstractChannel
|
||||
public void notifyError(SSHException error) {
|
||||
log.debug("Channel #{} got notified of {}", getID(), error.toString());
|
||||
|
||||
ErrorDeliveryUtil.alertEvents(error, open, close);
|
||||
ErrorDeliveryUtil.alertEvents(error, openEvent, closeEvent);
|
||||
ErrorDeliveryUtil.alertEvents(error, chanReqResponseEvents);
|
||||
|
||||
in.notifyError(error);
|
||||
@@ -256,35 +256,37 @@ public abstract class AbstractChannel
|
||||
@Override
|
||||
public void close()
|
||||
throws ConnectionException, TransportException {
|
||||
lock.lock();
|
||||
openCloseLock.lock();
|
||||
try {
|
||||
try {
|
||||
sendClose();
|
||||
} catch (TransportException e) {
|
||||
if (!close.inError())
|
||||
throw e;
|
||||
if (isOpen()) {
|
||||
try {
|
||||
sendClose();
|
||||
} catch (TransportException e) {
|
||||
if (!closeEvent.inError())
|
||||
throw e;
|
||||
}
|
||||
closeEvent.await(conn.getTimeout(), TimeUnit.SECONDS);
|
||||
}
|
||||
close.await(conn.getTimeout(), TimeUnit.SECONDS);
|
||||
} finally {
|
||||
lock.unlock();
|
||||
openCloseLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
public void join()
|
||||
throws ConnectionException {
|
||||
close.await();
|
||||
closeEvent.await();
|
||||
}
|
||||
|
||||
public void join(int timeout, TimeUnit unit)
|
||||
throws ConnectionException {
|
||||
close.await(timeout, unit);
|
||||
closeEvent.await(timeout, unit);
|
||||
}
|
||||
|
||||
protected synchronized void sendClose()
|
||||
throws TransportException {
|
||||
try {
|
||||
if (!closeRequested) {
|
||||
log.info("Sending close");
|
||||
log.debug("Sending close");
|
||||
trans.write(newBuffer(Message.CHANNEL_CLOSE));
|
||||
}
|
||||
} finally {
|
||||
@@ -294,11 +296,11 @@ public abstract class AbstractChannel
|
||||
|
||||
@Override
|
||||
public synchronized boolean isOpen() {
|
||||
lock.lock();
|
||||
openCloseLock.lock();
|
||||
try {
|
||||
return open.isSet() && !close.isSet() && !closeRequested;
|
||||
return openEvent.isSet() && !closeEvent.isSet() && !closeRequested;
|
||||
} finally {
|
||||
lock.unlock();
|
||||
openCloseLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -311,7 +313,7 @@ public abstract class AbstractChannel
|
||||
} catch (Buffer.BufferException be) {
|
||||
throw new ConnectionException(be);
|
||||
}
|
||||
log.info("Got chan request for `{}`", reqType);
|
||||
log.debug("Got chan request for `{}`", reqType);
|
||||
handleRequest(reqType, buf);
|
||||
}
|
||||
|
||||
@@ -323,13 +325,13 @@ public abstract class AbstractChannel
|
||||
} catch (Buffer.BufferException be) {
|
||||
throw new ConnectionException(be);
|
||||
}
|
||||
log.info("Received window adjustment for {} bytes", howMuch);
|
||||
log.debug("Received window adjustment for {} bytes", howMuch);
|
||||
rwin.expand(howMuch);
|
||||
}
|
||||
|
||||
protected void finishOff() {
|
||||
conn.forget(this);
|
||||
close.set();
|
||||
closeEvent.set();
|
||||
}
|
||||
|
||||
protected void gotExtendedData(SSHPacket buf)
|
||||
@@ -369,7 +371,7 @@ public abstract class AbstractChannel
|
||||
protected Event<ConnectionException> sendChannelRequest(String reqType, boolean wantReply,
|
||||
Buffer.PlainBuffer reqSpecific)
|
||||
throws TransportException {
|
||||
log.info("Sending channel request for `{}`", reqType);
|
||||
log.debug("Sending channel request for `{}`", reqType);
|
||||
synchronized (chanReqResponseEvents) {
|
||||
trans.write(
|
||||
newBuffer(Message.CHANNEL_REQUEST)
|
||||
@@ -381,7 +383,7 @@ public abstract class AbstractChannel
|
||||
Event<ConnectionException> responseEvent = null;
|
||||
if (wantReply) {
|
||||
responseEvent = new Event<ConnectionException>("chan#" + id + " / " + "chanreq for " + reqType,
|
||||
ConnectionException.chainer);
|
||||
ConnectionException.chainer);
|
||||
chanReqResponseEvents.add(responseEvent);
|
||||
}
|
||||
return responseEvent;
|
||||
@@ -399,13 +401,13 @@ public abstract class AbstractChannel
|
||||
responseEvent.deliverError(new ConnectionException("Request failed"));
|
||||
} else
|
||||
throw new ConnectionException(DisconnectReason.PROTOCOL_ERROR,
|
||||
"Received response to channel request when none was requested");
|
||||
"Received response to channel request when none was requested");
|
||||
}
|
||||
}
|
||||
|
||||
private synchronized void gotEOF()
|
||||
throws TransportException {
|
||||
log.info("Got EOF");
|
||||
log.debug("Got EOF");
|
||||
eofGot = true;
|
||||
eofInputStreams();
|
||||
if (eofSent)
|
||||
@@ -422,7 +424,7 @@ public abstract class AbstractChannel
|
||||
throws TransportException {
|
||||
try {
|
||||
if (!closeRequested && !eofSent) {
|
||||
log.info("Sending EOF");
|
||||
log.debug("Sending EOF");
|
||||
trans.write(newBuffer(Message.CHANNEL_EOF));
|
||||
if (eofGot)
|
||||
sendClose();
|
||||
|
||||
@@ -161,7 +161,7 @@ public final class ChannelInputStream
|
||||
synchronized (win) {
|
||||
final long adjustment = win.neededAdjustment();
|
||||
if (adjustment > 0) {
|
||||
log.info("Sending SSH_MSG_CHANNEL_WINDOW_ADJUST to #{} for {} bytes", chan.getRecipient(), adjustment);
|
||||
log.debug("Sending SSH_MSG_CHANNEL_WINDOW_ADJUST to #{} for {} bytes", chan.getRecipient(), adjustment);
|
||||
trans.write(new SSHPacket(Message.CHANNEL_WINDOW_ADJUST)
|
||||
.putUInt32(chan.getRecipient()).putUInt32(adjustment));
|
||||
win.expand(adjustment);
|
||||
|
||||
@@ -65,7 +65,7 @@ public abstract class AbstractDirectChannel
|
||||
public void open()
|
||||
throws ConnectionException, TransportException {
|
||||
trans.write(buildOpenReq());
|
||||
open.await(conn.getTimeout(), TimeUnit.SECONDS);
|
||||
openEvent.await(conn.getTimeout(), TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
private void gotOpenConfirmation(SSHPacket buf)
|
||||
@@ -75,13 +75,13 @@ public abstract class AbstractDirectChannel
|
||||
} catch (Buffer.BufferException be) {
|
||||
throw new ConnectionException(be);
|
||||
}
|
||||
open.set();
|
||||
openEvent.set();
|
||||
}
|
||||
|
||||
private void gotOpenFailure(SSHPacket buf)
|
||||
throws ConnectionException {
|
||||
try {
|
||||
open.deliverError(new OpenFailException(getType(), buf.readUInt32AsInt(), buf.readString()));
|
||||
openEvent.deliverError(new OpenFailException(getType(), buf.readUInt32AsInt(), buf.readString()));
|
||||
} catch (Buffer.BufferException be) {
|
||||
throw new ConnectionException(be);
|
||||
}
|
||||
|
||||
@@ -129,10 +129,10 @@ public class LocalPortForwarder {
|
||||
log.info("Listening on {}", serverSocket.getLocalSocketAddress());
|
||||
while (!Thread.currentThread().isInterrupted()) {
|
||||
final Socket socket = serverSocket.accept();
|
||||
log.info("Got connection from {}", socket.getRemoteSocketAddress());
|
||||
log.debug("Got connection from {}", socket.getRemoteSocketAddress());
|
||||
openChannel(socket).start();
|
||||
}
|
||||
log.info("Interrupted!");
|
||||
log.debug("Interrupted!");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -66,20 +66,20 @@ public abstract class AbstractForwardedChannel
|
||||
@Override
|
||||
public void confirm()
|
||||
throws TransportException {
|
||||
log.info("Confirming `{}` channel #{}", getType(), getID());
|
||||
log.debug("Confirming `{}` channel #{}", getType(), getID());
|
||||
// Must ensure channel is attached before confirming, data could start coming in immediately!
|
||||
conn.attach(this);
|
||||
trans.write(newBuffer(Message.CHANNEL_OPEN_CONFIRMATION)
|
||||
.putUInt32(getID())
|
||||
.putUInt32(getLocalWinSize())
|
||||
.putUInt32(getLocalMaxPacketSize()));
|
||||
open.set();
|
||||
openEvent.set();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reject(Reason reason, String message)
|
||||
throws TransportException {
|
||||
log.info("Rejecting `{}` channel: {}", getType(), message);
|
||||
log.debug("Rejecting `{}` channel: {}", getType(), message);
|
||||
conn.sendOpenFailure(getRecipient(), reason, message);
|
||||
}
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ public class SocketForwardingConnectListener
|
||||
@Override
|
||||
public void gotConnect(Channel.Forwarded chan)
|
||||
throws IOException {
|
||||
log.info("New connection from {}:{}", chan.getOriginatorIP(), chan.getOriginatorPort());
|
||||
log.debug("New connection from {}:{}", chan.getOriginatorIP(), chan.getOriginatorPort());
|
||||
|
||||
final Socket sock = new Socket();
|
||||
sock.setSendBufferSize(chan.getLocalMaxPacketSize());
|
||||
|
||||
@@ -15,16 +15,15 @@
|
||||
*/
|
||||
package net.schmizz.sshj.sftp;
|
||||
|
||||
import net.schmizz.concurrent.Promise;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import net.schmizz.concurrent.Promise;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class PacketReader
|
||||
extends Thread {
|
||||
|
||||
@@ -57,27 +56,25 @@ public class PacketReader
|
||||
throws IOException {
|
||||
readIntoBuffer(lenBuf, 0, lenBuf.length);
|
||||
|
||||
return (int) (lenBuf[0] << 24 & 0xff000000L
|
||||
final long len = (lenBuf[0] << 24 & 0xff000000L
|
||||
| lenBuf[1] << 16 & 0x00ff0000L
|
||||
| lenBuf[2] << 8 & 0x0000ff00L
|
||||
| lenBuf[3] & 0x000000ffL);
|
||||
|
||||
if (len > SFTPPacket.MAX_SIZE) {
|
||||
throw new IllegalStateException("Invalid packet: indicated length "+len+" too large");
|
||||
}
|
||||
|
||||
return (int) len;
|
||||
}
|
||||
|
||||
public SFTPPacket<Response> readPacket()
|
||||
throws IOException {
|
||||
int len = getPacketLength();
|
||||
if (len > SFTPPacket.MAX_SIZE) {
|
||||
throw new IllegalStateException("Invalid packet: indicated length "+len+" too large");
|
||||
}
|
||||
|
||||
packet.rpos(0);
|
||||
packet.wpos(0);
|
||||
|
||||
final int len = getPacketLength();
|
||||
packet.clear();
|
||||
packet.ensureCapacity(len);
|
||||
readIntoBuffer(packet.array(), 0, len);
|
||||
|
||||
packet.wpos(len);
|
||||
|
||||
return packet;
|
||||
}
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ public abstract class RemoteResource
|
||||
@Override
|
||||
public void close()
|
||||
throws IOException {
|
||||
log.info("Closing `{}`", this);
|
||||
log.debug("Closing `{}`", this);
|
||||
requester.doRequest(newRequest(PacketType.CLOSE)).ensureStatusPacketIsOK();
|
||||
}
|
||||
|
||||
|
||||
@@ -81,7 +81,7 @@ public class SFTPEngine
|
||||
throw new SFTPException("Expected INIT packet, received: " + type);
|
||||
|
||||
operativeVersion = response.readUInt32AsInt();
|
||||
log.info("Server version {}", operativeVersion);
|
||||
log.debug("Server version {}", operativeVersion);
|
||||
if (MAX_SUPPORTED_VERSION < operativeVersion)
|
||||
throw new SFTPException("Server reported incompatible protocol version: " + operativeVersion);
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ public class StatefulSFTPClient
|
||||
throws IOException {
|
||||
super(engine);
|
||||
this.cwd = getSFTPEngine().canonicalize(".");
|
||||
log.info("Start dir = {}", cwd);
|
||||
log.debug("Start dir = {}", cwd);
|
||||
}
|
||||
|
||||
private synchronized String cwdify(String path) {
|
||||
@@ -44,7 +44,7 @@ public class StatefulSFTPClient
|
||||
if (statExistence(cwd) == null) {
|
||||
throw new SFTPException(cwd + ": does not exist");
|
||||
}
|
||||
log.info("CWD = {}", cwd);
|
||||
log.debug("CWD = {}", cwd);
|
||||
}
|
||||
|
||||
public synchronized List<RemoteResourceInfo> ls()
|
||||
|
||||
@@ -166,7 +166,7 @@ final class Decoder
|
||||
}
|
||||
|
||||
if (isInvalidPacketLength(len)) { // Check packet length validity
|
||||
log.info("Error decoding packet (invalid length) {}", inputBuffer.printHex());
|
||||
log.error("Error decoding packet (invalid length) {}", inputBuffer.printHex());
|
||||
throw new TransportException(DisconnectReason.PROTOCOL_ERROR, "invalid packet length: " + len);
|
||||
}
|
||||
|
||||
|
||||
@@ -80,7 +80,7 @@ final class Heartbeater
|
||||
while (!isInterrupted()) {
|
||||
final int hi = getPositiveInterval();
|
||||
if (trans.isRunning()) {
|
||||
log.info("Sending heartbeat since {} seconds elapsed", hi);
|
||||
log.debug("Sending heartbeat since {} seconds elapsed", hi);
|
||||
trans.write(new SSHPacket(Message.IGNORE));
|
||||
}
|
||||
Thread.sleep(hi * 1000);
|
||||
|
||||
@@ -192,7 +192,7 @@ final class KeyExchanger
|
||||
*/
|
||||
private void sendKexInit()
|
||||
throws TransportException {
|
||||
log.info("Sending SSH_MSG_KEXINIT");
|
||||
log.debug("Sending SSH_MSG_KEXINIT");
|
||||
clientProposal = new Proposal(transport.getConfig());
|
||||
transport.write(clientProposal.getPacket());
|
||||
kexInitSent.set();
|
||||
@@ -200,7 +200,7 @@ final class KeyExchanger
|
||||
|
||||
private void sendNewKeys()
|
||||
throws TransportException {
|
||||
log.info("Sending SSH_MSG_NEWKEYS");
|
||||
log.debug("Sending SSH_MSG_NEWKEYS");
|
||||
transport.write(new SSHPacket(Message.NEWKEYS));
|
||||
}
|
||||
|
||||
@@ -354,7 +354,7 @@ final class KeyExchanger
|
||||
|
||||
case KEXINIT:
|
||||
ensureReceivedMatchesExpected(msg, Message.KEXINIT);
|
||||
log.info("Received SSH_MSG_KEXINIT");
|
||||
log.debug("Received SSH_MSG_KEXINIT");
|
||||
startKex(false); // Will start key exchange if not already on
|
||||
/*
|
||||
* We block on this event to prevent a race condition where we may have received a SSH_MSG_KEXINIT before
|
||||
@@ -367,7 +367,7 @@ final class KeyExchanger
|
||||
|
||||
case FOLLOWUP:
|
||||
ensureKexOngoing();
|
||||
log.info("Received kex followup data");
|
||||
log.debug("Received kex followup data");
|
||||
try {
|
||||
if (kex.next(msg, buf)) {
|
||||
verifyHost(kex.getHostKey());
|
||||
@@ -382,7 +382,7 @@ final class KeyExchanger
|
||||
case NEWKEYS:
|
||||
ensureReceivedMatchesExpected(msg, Message.NEWKEYS);
|
||||
ensureKexOngoing();
|
||||
log.info("Received SSH_MSG_NEWKEYS");
|
||||
log.debug("Received SSH_MSG_NEWKEYS");
|
||||
gotNewKeys();
|
||||
setKexDone();
|
||||
expected = Expected.KEXINIT;
|
||||
|
||||
@@ -90,7 +90,7 @@ public final class TransportImpl
|
||||
private final DisconnectListener nullDisconnectListener = new DisconnectListener() {
|
||||
@Override
|
||||
public void notifyDisconnect(DisconnectReason reason) {
|
||||
log.debug("Default disconnect listener - {}", reason);
|
||||
log.info("Disconnected - {}", reason);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -299,7 +299,7 @@ public final class TransportImpl
|
||||
if (service == null)
|
||||
service = nullService;
|
||||
|
||||
log.info("Setting active service to {}", service.getName());
|
||||
log.debug("Setting active service to {}", service.getName());
|
||||
this.service = service;
|
||||
}
|
||||
|
||||
@@ -346,7 +346,7 @@ public final class TransportImpl
|
||||
public long sendUnimplemented()
|
||||
throws TransportException {
|
||||
final long seq = decoder.getSequenceNumber();
|
||||
log.info("Sending SSH_MSG_UNIMPLEMENTED for packet #{}", seq);
|
||||
log.debug("Sending SSH_MSG_UNIMPLEMENTED for packet #{}", seq);
|
||||
return write(new SSHPacket(Message.UNIMPLEMENTED).putUInt32(seq));
|
||||
}
|
||||
|
||||
@@ -483,7 +483,7 @@ public final class TransportImpl
|
||||
break;
|
||||
}
|
||||
case IGNORE: {
|
||||
log.info("Received SSH_MSG_IGNORE");
|
||||
log.debug("Received SSH_MSG_IGNORE");
|
||||
break;
|
||||
}
|
||||
case UNIMPLEMENTED: {
|
||||
@@ -508,7 +508,7 @@ public final class TransportImpl
|
||||
try {
|
||||
final boolean display = buf.readBoolean();
|
||||
final String message = buf.readString();
|
||||
log.info("Received SSH_MSG_DEBUG (display={}) '{}'", display, message);
|
||||
log.debug("Received SSH_MSG_DEBUG (display={}) '{}'", display, message);
|
||||
} catch (Buffer.BufferException be) {
|
||||
throw new TransportException(be);
|
||||
}
|
||||
@@ -549,7 +549,7 @@ public final class TransportImpl
|
||||
private void gotUnimplemented(SSHPacket buf)
|
||||
throws SSHException {
|
||||
long seqNum = buf.readUInt32();
|
||||
log.info("Received SSH_MSG_UNIMPLEMENTED #{}", seqNum);
|
||||
log.debug("Received SSH_MSG_UNIMPLEMENTED #{}", seqNum);
|
||||
if (kexer.isKexOngoing())
|
||||
throw new TransportException("Received SSH_MSG_UNIMPLEMENTED while exchanging keys");
|
||||
getService().notifyUnimplemented(seqNum);
|
||||
|
||||
@@ -107,7 +107,7 @@ public abstract class AbstractDHG
|
||||
sha1.init();
|
||||
initDH(dh);
|
||||
|
||||
log.info("Sending SSH_MSG_KEXDH_INIT");
|
||||
log.debug("Sending SSH_MSG_KEXDH_INIT");
|
||||
trans.write(new SSHPacket(Message.KEXDH_INIT).putMPInt(dh.getE()));
|
||||
}
|
||||
|
||||
@@ -117,7 +117,7 @@ public abstract class AbstractDHG
|
||||
if (msg != Message.KEXDH_31)
|
||||
throw new TransportException(DisconnectReason.KEY_EXCHANGE_FAILED, "Unexpected packet: " + msg);
|
||||
|
||||
log.info("Received SSH_MSG_KEXDH_REPLY");
|
||||
log.debug("Received SSH_MSG_KEXDH_REPLY");
|
||||
final byte[] K_S;
|
||||
final BigInteger f;
|
||||
final byte[] sig; // signature sent by server
|
||||
|
||||
@@ -82,7 +82,7 @@ public class UserAuthImpl
|
||||
continue;
|
||||
}
|
||||
|
||||
log.info("Trying `{}` auth...", meth.getName());
|
||||
log.debug("Trying `{}` auth...", meth.getName());
|
||||
authenticated.clear();
|
||||
currentMethod = meth;
|
||||
|
||||
@@ -93,13 +93,13 @@ public class UserAuthImpl
|
||||
authenticated.await(timeout, TimeUnit.SECONDS);
|
||||
|
||||
} catch (UserAuthException e) {
|
||||
log.info("`{}` auth failed", meth.getName());
|
||||
log.debug("`{}` auth failed", meth.getName());
|
||||
// Give other methods a shot
|
||||
saveException(e);
|
||||
continue;
|
||||
}
|
||||
|
||||
log.info("`{}` auth successful", meth.getName());
|
||||
log.debug("`{}` auth successful", meth.getName());
|
||||
trans.setAuthenticated(); // So it can put delayed compression into force if applicable
|
||||
trans.setService(nextService); // We aren't in charge anymore, next service is
|
||||
return;
|
||||
|
||||
@@ -74,7 +74,7 @@ public class AuthKeyboardInteractive
|
||||
for (int i = 0; i < numPrompts; i++) {
|
||||
final String prompt = buf.readString();
|
||||
final boolean echo = buf.readBoolean();
|
||||
log.info("Requesting response for challenge `{}`; echo={}", prompt, echo);
|
||||
log.debug("Requesting response for challenge `{}`; echo={}", prompt, echo);
|
||||
userReplies[i] = new CharArrWrap(provider.getResponse(prompt, echo));
|
||||
}
|
||||
} catch (Buffer.BufferException be) {
|
||||
|
||||
@@ -37,7 +37,7 @@ public class AuthPassword
|
||||
public SSHPacket buildReq()
|
||||
throws UserAuthException {
|
||||
final AccountResource accountResource = makeAccountResource();
|
||||
log.info("Requesting password for {}", accountResource);
|
||||
log.debug("Requesting password for {}", accountResource);
|
||||
return super.buildReq() // the generic stuff
|
||||
.putBoolean(false) // no, we are not responding to a CHANGEREQ
|
||||
.putSensitiveString(pwdf.reqPassword(accountResource));
|
||||
|
||||
@@ -20,33 +20,31 @@ import net.schmizz.sshj.userauth.password.Resource;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class PasswordResponseProvider
|
||||
implements ChallengeResponseProvider {
|
||||
|
||||
public static final Pattern DEFAULT_PROMPT_PATTERN = Pattern.compile(".*[pP]assword:\\s?\\z");
|
||||
|
||||
private final Logger log = LoggerFactory.getLogger(getClass());
|
||||
|
||||
private static final char[] EMPTY_RESPONSE = new char[0];
|
||||
|
||||
private static final Collection<String> DEFAULT_ACCEPTABLE_PROMPTS =
|
||||
Collections.unmodifiableCollection(Arrays.asList("Password:", "Password: "));
|
||||
|
||||
private final Collection<String> acceptablePrompts;
|
||||
private final Pattern promptPattern;
|
||||
private final PasswordFinder pwdf;
|
||||
|
||||
private Resource resource;
|
||||
private boolean gaveAlready;
|
||||
|
||||
public PasswordResponseProvider(PasswordFinder pwdf) {
|
||||
this(pwdf, DEFAULT_ACCEPTABLE_PROMPTS);
|
||||
this(pwdf, DEFAULT_PROMPT_PATTERN);
|
||||
}
|
||||
|
||||
public PasswordResponseProvider(PasswordFinder pwdf, Collection<String> acceptablePrompts) {
|
||||
public PasswordResponseProvider(PasswordFinder pwdf, Pattern promptPattern) {
|
||||
this.pwdf = pwdf;
|
||||
this.acceptablePrompts = acceptablePrompts;
|
||||
this.promptPattern = promptPattern;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -62,8 +60,7 @@ public class PasswordResponseProvider
|
||||
|
||||
@Override
|
||||
public char[] getResponse(String prompt, boolean echo) {
|
||||
if (!gaveAlready && !echo && acceptablePrompts.contains(prompt)) {
|
||||
gaveAlready = true;
|
||||
if (!echo && promptPattern.matcher(prompt).matches()) {
|
||||
return pwdf.reqPassword(resource);
|
||||
}
|
||||
return EMPTY_RESPONSE;
|
||||
@@ -74,4 +71,4 @@ public class PasswordResponseProvider
|
||||
return pwdf.shouldRetry(resource);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,8 +45,6 @@ public interface FileTransfer {
|
||||
|
||||
/**
|
||||
* Upload {@code localFile} to {@code remotePath}.
|
||||
* <p/>
|
||||
* Attributes will be set on {@code remotePath} based on the {@code localFile}.
|
||||
*
|
||||
* @param localFile
|
||||
* @param remotePath
|
||||
@@ -58,8 +56,6 @@ public interface FileTransfer {
|
||||
|
||||
/**
|
||||
* Download {@code remotePath} to {@code localFile}.
|
||||
* <p/>
|
||||
* Attributes will be set on {@code localFile} based on the {@code remotePath}'s attributes.
|
||||
*
|
||||
* @param localFile
|
||||
* @param remotePath
|
||||
|
||||
@@ -23,20 +23,20 @@ public class LoggingTransferListener
|
||||
|
||||
@Override
|
||||
public TransferListener directory(String name) {
|
||||
log.info("started transferring directory `{}`", name);
|
||||
log.debug("started transferring directory `{}`", name);
|
||||
return new LoggingTransferListener(relPath + name + "/");
|
||||
}
|
||||
|
||||
@Override
|
||||
public StreamCopier.Listener file(final String name, final long size) {
|
||||
final String path = relPath + name;
|
||||
log.info("started transferring file `{}` ({} bytes)", path, size);
|
||||
log.debug("started transferring file `{}` ({} bytes)", path, size);
|
||||
return new StreamCopier.Listener() {
|
||||
@Override
|
||||
public void reportProgress(long transferred)
|
||||
throws IOException {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("transferred {}% of `{}`", ((transferred * 100) / size), path);
|
||||
if (log.isTraceEnabled()) {
|
||||
log.trace("transferred {}% of `{}`", ((transferred * 100) / size), path);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user