diff --git a/src/main/java/examples/LocalPF.java b/src/main/java/examples/LocalPF.java index dde122e8..233ea281 100644 --- a/src/main/java/examples/LocalPF.java +++ b/src/main/java/examples/LocalPF.java @@ -42,7 +42,7 @@ public class LocalPF { * google.com:80 */ ssh.newLocalPortForwarder(new InetSocketAddress("localhost", 8080), "google.com", 80) - .listen(); + .listen(); } finally { ssh.disconnect(); diff --git a/src/main/java/net/schmizz/concurrent/ErrorDeliveryUtil.java b/src/main/java/net/schmizz/concurrent/ErrorDeliveryUtil.java index a8ba77d0..aa317c34 100644 --- a/src/main/java/net/schmizz/concurrent/ErrorDeliveryUtil.java +++ b/src/main/java/net/schmizz/concurrent/ErrorDeliveryUtil.java @@ -30,12 +30,12 @@ public class ErrorDeliveryUtil { } public static void alertEvents(Throwable x, Event... events) { - for (Event e: events) + for (Event e : events) e.deliverError(x); } public static void alertEvents(Throwable x, Collection events) { - for (Event e: events) + for (Event e : events) e.deliverError(x); } diff --git a/src/main/java/net/schmizz/sshj/AndroidConfig.java b/src/main/java/net/schmizz/sshj/AndroidConfig.java index 00b9dd4e..387001c6 100644 --- a/src/main/java/net/schmizz/sshj/AndroidConfig.java +++ b/src/main/java/net/schmizz/sshj/AndroidConfig.java @@ -18,7 +18,8 @@ package net.schmizz.sshj; import net.schmizz.sshj.transport.random.JCERandom; import net.schmizz.sshj.transport.random.SingletonRandomFactory; -public class AndroidConfig extends DefaultConfig { +public class AndroidConfig + extends DefaultConfig { @Override protected void initRandomFactory(boolean ignored) { diff --git a/src/main/java/net/schmizz/sshj/Config.java b/src/main/java/net/schmizz/sshj/Config.java index aefa4a58..b9007b73 100644 --- a/src/main/java/net/schmizz/sshj/Config.java +++ b/src/main/java/net/schmizz/sshj/Config.java @@ -31,6 +31,7 @@ import java.util.List; * {@link Compression}, {@link MAC}, {@link Signature}, {@link Random}, and {@link FileKeyProvider}. */ public interface Config { + /** * Retrieve the list of named factories for {@code Cipher}. * diff --git a/src/main/java/net/schmizz/sshj/DefaultConfig.java b/src/main/java/net/schmizz/sshj/DefaultConfig.java index 5293888d..fd76138a 100644 --- a/src/main/java/net/schmizz/sshj/DefaultConfig.java +++ b/src/main/java/net/schmizz/sshj/DefaultConfig.java @@ -137,7 +137,7 @@ public class DefaultConfig boolean warn = false; // Ref. https://issues.apache.org/jira/browse/SSHD-24 // "AES256 and AES192 requires unlimited cryptography extension" - for (Iterator> i = avail.iterator(); i.hasNext();) { + for (Iterator> i = avail.iterator(); i.hasNext(); ) { final Factory.Named f = i.next(); try { final Cipher c = f.create(); diff --git a/src/main/java/net/schmizz/sshj/SSHClient.java b/src/main/java/net/schmizz/sshj/SSHClient.java index dde11f1c..cea78812 100644 --- a/src/main/java/net/schmizz/sshj/SSHClient.java +++ b/src/main/java/net/schmizz/sshj/SSHClient.java @@ -16,7 +16,6 @@ package net.schmizz.sshj; -import net.schmizz.sshj.common.DisconnectReason; import net.schmizz.sshj.common.Factory; import net.schmizz.sshj.common.SSHException; import net.schmizz.sshj.common.SecurityUtils; @@ -50,7 +49,6 @@ import net.schmizz.sshj.userauth.keyprovider.FileKeyProvider; import net.schmizz.sshj.userauth.keyprovider.KeyPairWrapper; import net.schmizz.sshj.userauth.keyprovider.KeyProvider; import net.schmizz.sshj.userauth.keyprovider.KeyProviderUtil; -import net.schmizz.sshj.userauth.keyprovider.OpenSSHKeyFile; import net.schmizz.sshj.userauth.method.AuthKeyboardInteractive; import net.schmizz.sshj.userauth.method.AuthMethod; import net.schmizz.sshj.userauth.method.AuthPassword; @@ -65,8 +63,6 @@ import org.slf4j.LoggerFactory; import java.io.File; import java.io.IOException; -import java.io.Reader; -import java.io.StringReader; import java.net.SocketAddress; import java.security.KeyPair; import java.security.PublicKey; @@ -444,7 +440,7 @@ public class SSHClient /** * Utility function for createing a {@link KeyProvider} instance from given location on the file system. Creates a * one-off {@link PasswordFinder} using {@link PasswordUtils#createOneOff(char[])}, and calls {@link - * #loadKeys(String,PasswordFinder)}. + * #loadKeys(String, PasswordFinder)}. * * @param location location of the key file * @param passphrase passphrase as a char-array @@ -505,8 +501,8 @@ public class SSHClient } /** - * Creates a {@link KeyProvider} instance from passed strings. Currently only PKCS8 format - * private key files are supported (OpenSSH uses this format). + * Creates a {@link KeyProvider} instance from passed strings. Currently only PKCS8 format private key files are + * supported (OpenSSH uses this format). *

* * @param privateKey the private key as a string diff --git a/src/main/java/net/schmizz/sshj/common/Base64.java b/src/main/java/net/schmizz/sshj/common/Base64.java index 8d206563..5f6dbc5c 100644 --- a/src/main/java/net/schmizz/sshj/common/Base64.java +++ b/src/main/java/net/schmizz/sshj/common/Base64.java @@ -32,7 +32,8 @@ public class Base64 { * @see Base64 * @since 1.3 */ - public static class InputStream extends java.io.FilterInputStream { + public static class InputStream + extends java.io.FilterInputStream { private final boolean encode; // Encoding or decoding private int position; // Current position in the buffer @@ -99,7 +100,8 @@ public class Base64 { * @since 1.3 */ @Override - public int read() throws java.io.IOException { + public int read() + throws java.io.IOException { // Do we need to get data? if (position < 0) @@ -197,7 +199,8 @@ public class Base64 { * @since 1.3 */ @Override - public int read(byte[] dest, int off, int len) throws java.io.IOException { + public int read(byte[] dest, int off, int len) + throws java.io.IOException { int i; int b; for (i = 0; i < len; i++) { @@ -222,7 +225,8 @@ public class Base64 { * @see Base64 * @since 1.3 */ - public static class OutputStream extends java.io.FilterOutputStream { + public static class OutputStream + extends java.io.FilterOutputStream { private final boolean encode; private int position; @@ -289,7 +293,8 @@ public class Base64 { * @since 1.3 */ @Override - public void close() throws java.io.IOException { + public void close() + throws java.io.IOException { // 1. Ensure that pending characters are written flush(); @@ -308,7 +313,8 @@ public class Base64 { * @since 2.3 */ @Override - public void flush() throws java.io.IOException { + public void flush() + throws java.io.IOException { flushBase64(); super.flush(); } @@ -318,7 +324,8 @@ public class Base64 { * * @throws java.io.IOException if there's an error. */ - public void flushBase64() throws java.io.IOException { + public void flushBase64() + throws java.io.IOException { if (position > 0) if (encode) { out.write(encode3to4(b4, buffer, position, options)); @@ -346,7 +353,8 @@ public class Base64 { * @throws java.io.IOException if there's an error flushing * @since 1.5.1 */ - public void suspendEncoding() throws java.io.IOException { + public void suspendEncoding() + throws java.io.IOException { flushBase64(); suspendEncoding = true; } // end suspendEncoding @@ -361,7 +369,8 @@ public class Base64 { * @since 1.3 */ @Override - public void write(byte[] theBytes, int off, int len) throws java.io.IOException { + public void write(byte[] theBytes, int off, int len) + throws java.io.IOException { // Encoding suspended? if (suspendEncoding) { super.out.write(theBytes, off, len); @@ -383,7 +392,8 @@ public class Base64 { * @since 1.3 */ @Override - public void write(int theByte) throws java.io.IOException { + public void write(int theByte) + throws java.io.IOException { // Encoding suspended? if (suspendEncoding) { super.out.write(theByte); @@ -673,7 +683,8 @@ public class Base64 { * @throws java.io.IOException If bogus characters exist in source data * @since 1.3 */ - public static byte[] decode(byte[] source, int off, int len, int options) throws java.io.IOException { + public static byte[] decode(byte[] source, int off, int len, int options) + throws java.io.IOException { // Lots of error checking and exception throwing if (source == null) @@ -725,7 +736,7 @@ public class Base64 { else // There's a bad input character in the Base64 stream. throw new java.io.IOException(String.format("Bad Base64 input character '%c' in array position %d", - source[i], i)); + source[i], i)); } // each input character byte[] out = new byte[outBuffPosn]; @@ -743,7 +754,8 @@ public class Base64 { * @throws java.io.IOException If there is a problem * @since 1.4 */ - public static byte[] decode(String s) throws java.io.IOException { + public static byte[] decode(String s) + throws java.io.IOException { return decode(s, NO_OPTIONS); } @@ -759,7 +771,8 @@ public class Base64 { * @throws NullPointerException if s is null * @since 1.4 */ - public static byte[] decode(String s, int options) throws java.io.IOException { + public static byte[] decode(String s, int options) + throws java.io.IOException { if (s == null) throw new NullPointerException("Input string was null."); @@ -833,7 +846,8 @@ public class Base64 { * @throws java.io.IOException if there is an error * @since 2.2 */ - public static void decodeFileToFile(String infile, String outfile) throws java.io.IOException { + public static void decodeFileToFile(String infile, String outfile) + throws java.io.IOException { byte[] decoded = Base64.decodeFromFile(infile); java.io.OutputStream out = null; @@ -864,7 +878,8 @@ public class Base64 { * @throws java.io.IOException if there is an error * @since 2.1 */ - public static byte[] decodeFromFile(String filename) throws java.io.IOException { + public static byte[] decodeFromFile(String filename) + throws java.io.IOException { byte[] decodedData = null; Base64.InputStream bis = null; @@ -878,12 +893,12 @@ public class Base64 { // Check for size of file if (file.length() > Integer.MAX_VALUE) throw new java.io.IOException("File is too big for this convenience method (" + file.length() - + " bytes)."); + + " bytes)."); buffer = new byte[(int) file.length()]; // Open a stream bis = new Base64.InputStream(new java.io.BufferedInputStream(new java.io.FileInputStream(file)), - Base64.DECODE); + Base64.DECODE); // Read until done while ((numBytes = bis.read(buffer, length, 4096)) >= 0) @@ -918,7 +933,8 @@ public class Base64 { * @throws java.io.IOException if there is an error * @since 2.1 */ - public static void decodeToFile(String dataToDecode, String filename) throws java.io.IOException { + public static void decodeToFile(String dataToDecode, String filename) + throws java.io.IOException { Base64.OutputStream bos = null; try { @@ -950,8 +966,9 @@ public class Base64 { * @throws ClassNotFoundException if the decoded object is of a class that cannot be found by the JVM * @since 1.5 */ - public static Object decodeToObject(String encodedObject) throws java.io.IOException, - java.lang.ClassNotFoundException { + public static Object decodeToObject(String encodedObject) + throws java.io.IOException, + java.lang.ClassNotFoundException { // Decode and gunzip if necessary byte[] objBytes = decode(encodedObject); @@ -1078,7 +1095,8 @@ public class Base64 { * @see Base64#DO_BREAK_LINES * @since 2.0 */ - public static String encodeBytes(byte[] source, int options) throws java.io.IOException { + public static String encodeBytes(byte[] source, int options) + throws java.io.IOException { return encodeBytes(source, 0, source.length, options); } // end encodeBytes @@ -1137,7 +1155,8 @@ public class Base64 { * @see Base64#DO_BREAK_LINES * @since 2.0 */ - public static String encodeBytes(byte[] source, int off, int len, int options) throws java.io.IOException { + public static String encodeBytes(byte[] source, int off, int len, int options) + throws java.io.IOException { byte[] encoded = encodeBytesToBytes(source, off, len, options); // Return value according to relevant encoding. @@ -1189,7 +1208,8 @@ public class Base64 { * @see Base64#DO_BREAK_LINES * @since 2.3.1 */ - public static byte[] encodeBytesToBytes(byte[] source, int off, int len, int options) throws java.io.IOException { + public static byte[] encodeBytesToBytes(byte[] source, int off, int len, int options) + throws java.io.IOException { if (source == null) throw new NullPointerException("Cannot serialize a null array."); @@ -1302,7 +1322,8 @@ public class Base64 { * @throws java.io.IOException if there is an error * @since 2.2 */ - public static void encodeFileToFile(String infile, String outfile) throws java.io.IOException { + public static void encodeFileToFile(String infile, String outfile) + throws java.io.IOException { String encoded = Base64.encodeFromFile(infile); java.io.OutputStream out = null; @@ -1333,7 +1354,8 @@ public class Base64 { * @throws java.io.IOException if there is an error * @since 2.1 */ - public static String encodeFromFile(String filename) throws java.io.IOException { + public static String encodeFromFile(String filename) + throws java.io.IOException { String encodedData = null; Base64.InputStream bis = null; @@ -1348,7 +1370,7 @@ public class Base64 { // Open a stream bis = new Base64.InputStream(new java.io.BufferedInputStream(new java.io.FileInputStream(file)), - Base64.ENCODE); + Base64.ENCODE); // Read until done while ((numBytes = bis.read(buffer, length, 4096)) >= 0) @@ -1387,7 +1409,8 @@ public class Base64 { * @throws NullPointerException if serializedObject is null * @since 1.4 */ - public static String encodeObject(java.io.Serializable serializableObject) throws java.io.IOException { + public static String encodeObject(java.io.Serializable serializableObject) + throws java.io.IOException { return encodeObject(serializableObject, NO_OPTIONS); } // end encodeObject @@ -1420,7 +1443,8 @@ public class Base64 { * @see Base64#DO_BREAK_LINES * @since 2.0 */ - public static String encodeObject(java.io.Serializable serializableObject, int options) throws java.io.IOException { + public static String encodeObject(java.io.Serializable serializableObject, int options) + throws java.io.IOException { if (serializableObject == null) throw new NullPointerException("Cannot serialize a null object."); @@ -1481,7 +1505,8 @@ public class Base64 { * @throws NullPointerException if dataToEncode is null * @since 2.1 */ - public static void encodeToFile(byte[] dataToEncode, String filename) throws java.io.IOException { + public static void encodeToFile(byte[] dataToEncode, String filename) + throws java.io.IOException { if (dataToEncode == null) throw new NullPointerException("Data to encode was null."); diff --git a/src/main/java/net/schmizz/sshj/common/ByteArrayUtils.java b/src/main/java/net/schmizz/sshj/common/ByteArrayUtils.java index 5049bd78..cb74e05b 100644 --- a/src/main/java/net/schmizz/sshj/common/ByteArrayUtils.java +++ b/src/main/java/net/schmizz/sshj/common/ByteArrayUtils.java @@ -35,8 +35,6 @@ */ package net.schmizz.sshj.common; -import java.util.Arrays; - /** Utility functions for byte arrays. */ public class ByteArrayUtils { diff --git a/src/main/java/net/schmizz/sshj/common/ErrorNotifiable.java b/src/main/java/net/schmizz/sshj/common/ErrorNotifiable.java index 306455e7..2306a472 100644 --- a/src/main/java/net/schmizz/sshj/common/ErrorNotifiable.java +++ b/src/main/java/net/schmizz/sshj/common/ErrorNotifiable.java @@ -22,6 +22,7 @@ public interface ErrorNotifiable { /** Utility functions. */ class Util { + /** Notify all {@code notifiables} of given {@code error}. */ public static void alertAll(SSHException error, ErrorNotifiable... notifiables) { for (ErrorNotifiable notifiable : notifiables) diff --git a/src/main/java/net/schmizz/sshj/common/KeyType.java b/src/main/java/net/schmizz/sshj/common/KeyType.java index 4d955f11..3c3699bc 100644 --- a/src/main/java/net/schmizz/sshj/common/KeyType.java +++ b/src/main/java/net/schmizz/sshj/common/KeyType.java @@ -32,7 +32,6 @@ public enum KeyType { /** SSH identifier for RSA keys */ RSA("ssh-rsa") { - @Override public PublicKey readPubKeyFromBuffer(String type, Buffer buf) throws GeneralSecurityException { @@ -64,7 +63,6 @@ public enum KeyType { /** SSH identifier for DSA keys */ DSA("ssh-dss") { - @Override public PublicKey readPubKeyFromBuffer(String type, Buffer buf) throws GeneralSecurityException { @@ -100,7 +98,6 @@ public enum KeyType { /** Unrecognized */ UNKNOWN("unknown") { - @Override public PublicKey readPubKeyFromBuffer(String type, Buffer buf) throws GeneralSecurityException { diff --git a/src/main/java/net/schmizz/sshj/common/SecurityUtils.java b/src/main/java/net/schmizz/sshj/common/SecurityUtils.java index 7d253e86..374a21fe 100644 --- a/src/main/java/net/schmizz/sshj/common/SecurityUtils.java +++ b/src/main/java/net/schmizz/sshj/common/SecurityUtils.java @@ -58,6 +58,7 @@ import java.security.Signature; public class SecurityUtils { private static class BouncyCastleRegistration { + public void run() throws Exception { if (java.security.Security.getProvider(BOUNCY_CASTLE) == null) { diff --git a/src/main/java/net/schmizz/sshj/connection/Connection.java b/src/main/java/net/schmizz/sshj/connection/Connection.java index 538590f8..5eaff712 100644 --- a/src/main/java/net/schmizz/sshj/connection/Connection.java +++ b/src/main/java/net/schmizz/sshj/connection/Connection.java @@ -89,13 +89,13 @@ public interface Connection { * @param wantReply whether a reply is requested * @param specifics {@link SSHPacket} containing fields specific to the request * - * @return a {@link net.schmizz.concurrent.Promise} for the reply data (in case {@code wantReply} is true) which allows waiting on the - * reply, or {@code null} if a reply is not requested. + * @return a {@link net.schmizz.concurrent.Promise} for the reply data (in case {@code wantReply} is true) which + * allows waiting on the reply, or {@code null} if a reply is not requested. * * @throws TransportException if there is an error sending the request */ public Promise sendGlobalRequest(String name, boolean wantReply, - byte[] specifics) + byte[] specifics) throws TransportException; /** diff --git a/src/main/java/net/schmizz/sshj/connection/channel/AbstractChannel.java b/src/main/java/net/schmizz/sshj/connection/channel/AbstractChannel.java index e083caec..fe8d4c31 100644 --- a/src/main/java/net/schmizz/sshj/connection/channel/AbstractChannel.java +++ b/src/main/java/net/schmizz/sshj/connection/channel/AbstractChannel.java @@ -35,8 +35,8 @@ */ package net.schmizz.sshj.connection.channel; -import net.schmizz.concurrent.Event; import net.schmizz.concurrent.ErrorDeliveryUtil; +import net.schmizz.concurrent.Event; import net.schmizz.sshj.common.Buffer; import net.schmizz.sshj.common.ByteArrayUtils; import net.schmizz.sshj.common.DisconnectReason; @@ -313,7 +313,8 @@ public abstract class AbstractChannel handleRequest(reqType, buf); } - private void gotWindowAdjustment(SSHPacket buf) throws ConnectionException { + private void gotWindowAdjustment(SSHPacket buf) + throws ConnectionException { final int howMuch; try { howMuch = buf.readUInt32AsInt(); @@ -429,7 +430,7 @@ public abstract class AbstractChannel @Override public String toString() { return "< " + type + " channel: id=" + id + ", recipient=" + recipient + ", localWin=" + lwin + ", remoteWin=" - + rwin + " >"; + + rwin + " >"; } diff --git a/src/main/java/net/schmizz/sshj/connection/channel/Channel.java b/src/main/java/net/schmizz/sshj/connection/channel/Channel.java index 3f12b22f..8f9b8df1 100644 --- a/src/main/java/net/schmizz/sshj/connection/channel/Channel.java +++ b/src/main/java/net/schmizz/sshj/connection/channel/Channel.java @@ -32,6 +32,7 @@ public interface Channel /** Direct channels are those that are initiated by us. */ interface Direct extends Channel { + /** * Request opening this channel from remote end. * diff --git a/src/main/java/net/schmizz/sshj/connection/channel/ChannelInputStream.java b/src/main/java/net/schmizz/sshj/connection/channel/ChannelInputStream.java index b01c253e..054d8f50 100644 --- a/src/main/java/net/schmizz/sshj/connection/channel/ChannelInputStream.java +++ b/src/main/java/net/schmizz/sshj/connection/channel/ChannelInputStream.java @@ -116,7 +116,7 @@ public final class ChannelInputStream public int read(byte[] b, int off, int len) throws IOException { synchronized (buf) { - for (; ;) { + for (; ; ) { if (buf.available() > 0) break; if (eof) @@ -163,7 +163,7 @@ public final class ChannelInputStream if (adjustment > 0) { log.info("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)); + .putUInt32(chan.getRecipient()).putUInt32(adjustment)); win.expand(adjustment); } } diff --git a/src/main/java/net/schmizz/sshj/connection/channel/SocketStreamCopyMonitor.java b/src/main/java/net/schmizz/sshj/connection/channel/SocketStreamCopyMonitor.java index 48005cb6..d3b4a7ba 100644 --- a/src/main/java/net/schmizz/sshj/connection/channel/SocketStreamCopyMonitor.java +++ b/src/main/java/net/schmizz/sshj/connection/channel/SocketStreamCopyMonitor.java @@ -43,8 +43,8 @@ public class SocketStreamCopyMonitor } public static void monitor(final int frequency, final TimeUnit unit, - final Event x, final Event y, - final Channel channel, final Socket socket) { + final Event x, final Event y, + final Channel channel, final Socket socket) { new SocketStreamCopyMonitor(new Runnable() { public void run() { try { diff --git a/src/main/java/net/schmizz/sshj/connection/channel/direct/LocalPortForwarder.java b/src/main/java/net/schmizz/sshj/connection/channel/direct/LocalPortForwarder.java index f5381d84..3466fef5 100644 --- a/src/main/java/net/schmizz/sshj/connection/channel/direct/LocalPortForwarder.java +++ b/src/main/java/net/schmizz/sshj/connection/channel/direct/LocalPortForwarder.java @@ -53,7 +53,7 @@ public class LocalPortForwarder { .bufSize(getLocalMaxPacketSize()) .spawnDaemon("chan2soc"); SocketStreamCopyMonitor.monitor(5, TimeUnit.SECONDS, soc2chan, chan2soc, this, sock); - } + } @Override protected SSHPacket buildOpenReq() { diff --git a/src/main/java/net/schmizz/sshj/connection/channel/direct/Session.java b/src/main/java/net/schmizz/sshj/connection/channel/direct/Session.java index 8646c529..a5cef83a 100644 --- a/src/main/java/net/schmizz/sshj/connection/channel/direct/Session.java +++ b/src/main/java/net/schmizz/sshj/connection/channel/direct/Session.java @@ -82,10 +82,12 @@ public interface Session throws TransportException; @Deprecated - String getOutputAsString() throws IOException; + String getOutputAsString() + throws IOException; @Deprecated - String getErrorAsString() throws IOException; + String getErrorAsString() + throws IOException; } @@ -132,6 +134,7 @@ public interface Session /** Subsystem API. */ interface Subsystem extends Channel { + Integer getExitStatus(); } diff --git a/src/main/java/net/schmizz/sshj/connection/channel/forwarded/AbstractForwardedChannel.java b/src/main/java/net/schmizz/sshj/connection/channel/forwarded/AbstractForwardedChannel.java index 7caad5e5..6168d96d 100644 --- a/src/main/java/net/schmizz/sshj/connection/channel/forwarded/AbstractForwardedChannel.java +++ b/src/main/java/net/schmizz/sshj/connection/channel/forwarded/AbstractForwardedChannel.java @@ -69,9 +69,9 @@ public abstract class AbstractForwardedChannel // 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())); + .putUInt32(getID()) + .putUInt32(getLocalWinSize()) + .putUInt32(getLocalMaxPacketSize())); open.set(); } diff --git a/src/main/java/net/schmizz/sshj/connection/channel/forwarded/RemotePortForwarder.java b/src/main/java/net/schmizz/sshj/connection/channel/forwarded/RemotePortForwarder.java index a9dac9de..61462e51 100644 --- a/src/main/java/net/schmizz/sshj/connection/channel/forwarded/RemotePortForwarder.java +++ b/src/main/java/net/schmizz/sshj/connection/channel/forwarded/RemotePortForwarder.java @@ -39,18 +39,18 @@ public class RemotePortForwarder * address (or domain name) and port on which connections for forwarding * are to be accepted. Some strings used for 'address to bind' have * special-case semantics. - *

+ * * o "" means that connections are to be accepted on all protocol * families supported by the SSH implementation. - *

+ * * o "0.0.0.0" means to listen on all IPv4 addresses. - *

+ * * o "::" means to listen on all IPv6 addresses. - *

+ * * o "localhost" means to listen on all protocol families supported by * the SSH implementation on loopback addresses only ([RFC3330] and * [RFC3513]). - *

+ * * o "127.0.0.1" and "::1" indicate listening on the loopback * interfaces for IPv4 and IPv6, respectively. * @@ -198,9 +198,9 @@ public class RemotePortForwarder protected SSHPacket req(String reqName, Forward forward) throws ConnectionException, TransportException { final byte[] specifics = new Buffer.PlainBuffer().putString(forward.address).putUInt32(forward.port) - .getCompactData(); + .getCompactData(); return conn.sendGlobalRequest(reqName, true, specifics) - .retrieve(conn.getTimeout(), TimeUnit.SECONDS); + .retrieve(conn.getTimeout(), TimeUnit.SECONDS); } /** @return the active forwards. */ @@ -227,7 +227,7 @@ public class RemotePortForwarder callListener(listeners.get(chan.getParentForward()), chan); else chan.reject(OpenFailException.Reason.ADMINISTRATIVELY_PROHIBITED, "Forwarding was not requested on `" - + chan.getParentForward() + "`"); + + chan.getParentForward() + "`"); } } \ No newline at end of file diff --git a/src/main/java/net/schmizz/sshj/sftp/PacketReader.java b/src/main/java/net/schmizz/sshj/sftp/PacketReader.java index 71f7fe3f..02f85f64 100644 --- a/src/main/java/net/schmizz/sshj/sftp/PacketReader.java +++ b/src/main/java/net/schmizz/sshj/sftp/PacketReader.java @@ -57,9 +57,9 @@ public class PacketReader readIntoBuffer(lenBuf, 0, lenBuf.length); return (int) (lenBuf[0] << 24 & 0xff000000L - | lenBuf[1] << 16 & 0x00ff0000L - | lenBuf[2] << 8 & 0x0000ff00L - | lenBuf[3] & 0x000000ffL); + | lenBuf[1] << 16 & 0x00ff0000L + | lenBuf[2] << 8 & 0x0000ff00L + | lenBuf[3] & 0x000000ffL); } public SFTPPacket readPacket() @@ -97,7 +97,7 @@ public class PacketReader log.debug("Received {} packet", resp.getType()); if (promise == null) throw new SFTPException("Received [" + resp.readType() + "] response for request-id " + resp.getRequestID() - + ", no such request was made"); + + ", no such request was made"); else promise.deliver(resp); } diff --git a/src/main/java/net/schmizz/sshj/sftp/RemoteDirectory.java b/src/main/java/net/schmizz/sshj/sftp/RemoteDirectory.java index 9a8f2ecd..a999717d 100644 --- a/src/main/java/net/schmizz/sshj/sftp/RemoteDirectory.java +++ b/src/main/java/net/schmizz/sshj/sftp/RemoteDirectory.java @@ -32,7 +32,7 @@ public class RemoteDirectory throws IOException { List rri = new LinkedList(); loop: - for (; ;) { + for (; ; ) { Response res = requester.doRequest(newRequest(PacketType.READDIR)); switch (res.getType()) { diff --git a/src/main/java/net/schmizz/sshj/sftp/RemoteFile.java b/src/main/java/net/schmizz/sshj/sftp/RemoteFile.java index 64105573..dd2565c3 100644 --- a/src/main/java/net/schmizz/sshj/sftp/RemoteFile.java +++ b/src/main/java/net/schmizz/sshj/sftp/RemoteFile.java @@ -39,8 +39,8 @@ public class RemoteFile public FileAttributes fetchAttributes() throws IOException { return requester.doRequest(newRequest(PacketType.FSTAT)) - .ensurePacketTypeIs(PacketType.ATTRS) - .readFileAttributes(); + .ensurePacketTypeIs(PacketType.ATTRS) + .readFileAttributes(); } public long length() @@ -74,9 +74,9 @@ public class RemoteFile public void write(long fileOffset, byte[] data, int off, int len) throws IOException { requester.doRequest(newRequest(PacketType.WRITE) - .putUInt64(fileOffset) - .putUInt32(len - off) - .putRawBytes(data, off, len) + .putUInt64(fileOffset) + .putUInt32(len - off) + .putRawBytes(data, off, len) ).ensureStatusPacketIsOK(); } @@ -87,12 +87,12 @@ public class RemoteFile public int getOutgoingPacketOverhead() { return 1 + // packet type - 4 + // request id - 4 + // next length - handle.length() + // next - 8 + // file offset - 4 + // data length - 4; // packet length + 4 + // request id + 4 + // next length + handle.length() + // next + 8 + // file offset + 4 + // data length + 4; // packet length } public class RemoteFileOutputStream diff --git a/src/main/java/net/schmizz/sshj/sftp/Response.java b/src/main/java/net/schmizz/sshj/sftp/Response.java index bdd626aa..92ad141a 100644 --- a/src/main/java/net/schmizz/sshj/sftp/Response.java +++ b/src/main/java/net/schmizz/sshj/sftp/Response.java @@ -51,7 +51,8 @@ public class Response private final PacketType type; private final long reqID; - public Response(Buffer pk, int protocolVersion) throws SFTPException { + public Response(Buffer pk, int protocolVersion) + throws SFTPException { super(pk); this.protocolVersion = protocolVersion; this.type = readType(); @@ -74,7 +75,8 @@ public class Response return type; } - public StatusCode readStatusCode() throws SFTPException { + public StatusCode readStatusCode() + throws SFTPException { try { return StatusCode.fromInt(readUInt32AsInt()); } catch (BufferException be) { diff --git a/src/main/java/net/schmizz/sshj/sftp/SFTPEngine.java b/src/main/java/net/schmizz/sshj/sftp/SFTPEngine.java index 0e691db4..f2d3b40a 100644 --- a/src/main/java/net/schmizz/sshj/sftp/SFTPEngine.java +++ b/src/main/java/net/schmizz/sshj/sftp/SFTPEngine.java @@ -56,7 +56,8 @@ public class SFTPEngine this(ssh, PathHelper.DEFAULT_PATH_SEPARATOR); } - public SFTPEngine(SessionFactory ssh, String pathSep) throws SSHException { + public SFTPEngine(SessionFactory ssh, String pathSep) + throws SSHException { sub = ssh.startSession().startSubsystem("sftp"); out = sub.getOutputStream(); reader = new PacketReader(this); diff --git a/src/main/java/net/schmizz/sshj/transport/Converter.java b/src/main/java/net/schmizz/sshj/transport/Converter.java index 2c9c2830..cc3bde58 100644 --- a/src/main/java/net/schmizz/sshj/transport/Converter.java +++ b/src/main/java/net/schmizz/sshj/transport/Converter.java @@ -47,7 +47,7 @@ import net.schmizz.sshj.transport.mac.MAC; *

*

  *    Each packet is in the following format:
- * 

+ * * uint32 packet_length * byte padding_length * byte[n1] payload; n1 = packet_length - padding_length - 1 diff --git a/src/main/java/net/schmizz/sshj/transport/Decoder.java b/src/main/java/net/schmizz/sshj/transport/Decoder.java index 074583a1..de8f29ee 100644 --- a/src/main/java/net/schmizz/sshj/transport/Decoder.java +++ b/src/main/java/net/schmizz/sshj/transport/Decoder.java @@ -88,7 +88,7 @@ final class Decoder int need; /* Decoding loop */ - for (; ;) + for (; ; ) if (packetLength == -1) // Waiting for beginning of packet { @@ -124,7 +124,7 @@ final class Decoder if (log.isTraceEnabled()) log.trace("Received packet #{}: {}", seq, plain.printHex()); - packetHandler.handle(plain.readMessageID(), plain); // Process the decoded packet // + packetHandler.handle(plain.readMessageID(), plain); // Process the decoded packet inputBuffer.clear(); packetLength = -1; diff --git a/src/main/java/net/schmizz/sshj/transport/NegotiatedAlgorithms.java b/src/main/java/net/schmizz/sshj/transport/NegotiatedAlgorithms.java index dbe00bf7..f23dd395 100644 --- a/src/main/java/net/schmizz/sshj/transport/NegotiatedAlgorithms.java +++ b/src/main/java/net/schmizz/sshj/transport/NegotiatedAlgorithms.java @@ -92,15 +92,15 @@ public final class NegotiatedAlgorithms { @Override public String toString() { - return ("[ " + // - "kex=" + kex + "; " + // - "sig=" + sig + "; " + // - "c2sCipher=" + c2sCipher + "; " + // - "s2cCipher=" + s2cCipher + "; " + // - "c2sMAC=" + c2sMAC + "; " + // - "s2cMAC=" + s2cMAC + "; " + // - "c2sComp=" + c2sComp + "; " + // - "s2cComp=" + s2cComp + // + return ("[ " + + "kex=" + kex + "; " + + "sig=" + sig + "; " + + "c2sCipher=" + c2sCipher + "; " + + "s2cCipher=" + s2cCipher + "; " + + "c2sMAC=" + c2sMAC + "; " + + "s2cMAC=" + s2cMAC + "; " + + "c2sComp=" + c2sComp + "; " + + "s2cComp=" + s2cComp + " ]"); } diff --git a/src/main/java/net/schmizz/sshj/transport/Transport.java b/src/main/java/net/schmizz/sshj/transport/Transport.java index 6d465655..75d65538 100644 --- a/src/main/java/net/schmizz/sshj/transport/Transport.java +++ b/src/main/java/net/schmizz/sshj/transport/Transport.java @@ -178,12 +178,14 @@ public interface Transport */ void join() throws TransportException; + /** * Joins the thread calling this method to the transport's death. * * @throws TransportException if the transport dies of an exception */ - void join(int timeout, TimeUnit unit) throws TransportException; + void join(int timeout, TimeUnit unit) + throws TransportException; /** Send a disconnection packet with reason as {@link DisconnectReason#BY_APPLICATION}, and closes this transport. */ void disconnect(); @@ -226,9 +228,7 @@ public interface Transport */ void setDisconnectListener(DisconnectListener listener); - /** - * @return the current disconnect listener. - */ + /** @return the current disconnect listener. */ DisconnectListener getDisconnectListener(); } \ No newline at end of file diff --git a/src/main/java/net/schmizz/sshj/transport/TransportImpl.java b/src/main/java/net/schmizz/sshj/transport/TransportImpl.java index 67d2f0be..054ce034 100644 --- a/src/main/java/net/schmizz/sshj/transport/TransportImpl.java +++ b/src/main/java/net/schmizz/sshj/transport/TransportImpl.java @@ -35,8 +35,8 @@ */ package net.schmizz.sshj.transport; -import net.schmizz.concurrent.Event; import net.schmizz.concurrent.ErrorDeliveryUtil; +import net.schmizz.concurrent.Event; import net.schmizz.sshj.AbstractService; import net.schmizz.sshj.Config; import net.schmizz.sshj.Service; @@ -62,12 +62,14 @@ public final class TransportImpl private static final class NullService extends AbstractService { + NullService(Transport trans) { super("null-service", trans); } } static final class ConnInfo { + final String host; final int port; final InputStream in; @@ -185,11 +187,11 @@ public final class TransportImpl String ident; byte[] data = new byte[256]; - for (; ;) { + for (; ; ) { int savedBufPos = buffer.rpos(); int pos = 0; boolean needLF = false; - for (; ;) { + for (; ; ) { if (buffer.available() == 0) { // Need more data, so undo reading and return null buffer.rpos(savedBufPos); @@ -217,7 +219,7 @@ public final class TransportImpl if (!ident.startsWith("SSH-2.0-") && !ident.startsWith("SSH-1.99-")) throw new TransportException(DisconnectReason.PROTOCOL_VERSION_NOT_SUPPORTED, - "Server does not support SSHv2, identified as: " + ident); + "Server does not support SSHv2, identified as: " + ident); return ident; } @@ -438,9 +440,9 @@ public final class TransportImpl log.debug("Sending SSH_MSG_DISCONNECT: reason=[{}], msg=[{}]", reason, message); try { write(new SSHPacket(Message.DISCONNECT) - .putUInt32(reason.toInt()) - .putString(message) - .putString("")); + .putUInt32(reason.toInt()) + .putString(message) + .putString("")); } catch (IOException worthless) { log.debug("Error writing packet: {}", worthless.toString()); } @@ -501,7 +503,8 @@ public final class TransportImpl } } - private void gotDebug(SSHPacket buf) throws TransportException { + private void gotDebug(SSHPacket buf) + throws TransportException { try { final boolean display = buf.readBoolean(); final String message = buf.readString(); @@ -529,7 +532,7 @@ public final class TransportImpl try { if (!serviceAccept.hasWaiters()) throw new TransportException(DisconnectReason.PROTOCOL_ERROR, - "Got a service accept notification when none was awaited"); + "Got a service accept notification when none was awaited"); serviceAccept.set(); } finally { serviceAccept.unlock(); diff --git a/src/main/java/net/schmizz/sshj/transport/cipher/AES128CBC.java b/src/main/java/net/schmizz/sshj/transport/cipher/AES128CBC.java index ff3a2ddc..bc86df74 100644 --- a/src/main/java/net/schmizz/sshj/transport/cipher/AES128CBC.java +++ b/src/main/java/net/schmizz/sshj/transport/cipher/AES128CBC.java @@ -42,6 +42,7 @@ public class AES128CBC /** Named factory for AES128CBC Cipher */ public static class Factory implements net.schmizz.sshj.common.Factory.Named { + @Override public Cipher create() { return new AES128CBC(); diff --git a/src/main/java/net/schmizz/sshj/transport/cipher/AES128CTR.java b/src/main/java/net/schmizz/sshj/transport/cipher/AES128CTR.java index 255b4e5e..2ed3d39a 100644 --- a/src/main/java/net/schmizz/sshj/transport/cipher/AES128CTR.java +++ b/src/main/java/net/schmizz/sshj/transport/cipher/AES128CTR.java @@ -42,6 +42,7 @@ public class AES128CTR /** Named factory for AES128CBC Cipher */ public static class Factory implements net.schmizz.sshj.common.Factory.Named { + @Override public Cipher create() { return new AES128CTR(); diff --git a/src/main/java/net/schmizz/sshj/transport/cipher/AES192CBC.java b/src/main/java/net/schmizz/sshj/transport/cipher/AES192CBC.java index 67e884ea..22c67a52 100644 --- a/src/main/java/net/schmizz/sshj/transport/cipher/AES192CBC.java +++ b/src/main/java/net/schmizz/sshj/transport/cipher/AES192CBC.java @@ -42,6 +42,7 @@ public class AES192CBC /** Named factory for AES192CBC Cipher */ public static class Factory implements net.schmizz.sshj.common.Factory.Named { + @Override public Cipher create() { return new AES192CBC(); diff --git a/src/main/java/net/schmizz/sshj/transport/cipher/AES192CTR.java b/src/main/java/net/schmizz/sshj/transport/cipher/AES192CTR.java index 9e7bab4f..2fc9549f 100644 --- a/src/main/java/net/schmizz/sshj/transport/cipher/AES192CTR.java +++ b/src/main/java/net/schmizz/sshj/transport/cipher/AES192CTR.java @@ -42,6 +42,7 @@ public class AES192CTR /** Named factory for AES192CTR Cipher */ public static class Factory implements net.schmizz.sshj.common.Factory.Named { + @Override public Cipher create() { return new AES192CTR(); diff --git a/src/main/java/net/schmizz/sshj/transport/cipher/AES256CBC.java b/src/main/java/net/schmizz/sshj/transport/cipher/AES256CBC.java index b25178b3..bc7d049e 100644 --- a/src/main/java/net/schmizz/sshj/transport/cipher/AES256CBC.java +++ b/src/main/java/net/schmizz/sshj/transport/cipher/AES256CBC.java @@ -42,6 +42,7 @@ public class AES256CBC /** Named factory for AES256CBC Cipher */ public static class Factory implements net.schmizz.sshj.common.Factory.Named { + @Override public Cipher create() { return new AES256CBC(); diff --git a/src/main/java/net/schmizz/sshj/transport/cipher/AES256CTR.java b/src/main/java/net/schmizz/sshj/transport/cipher/AES256CTR.java index f2752c0d..fdd50d56 100644 --- a/src/main/java/net/schmizz/sshj/transport/cipher/AES256CTR.java +++ b/src/main/java/net/schmizz/sshj/transport/cipher/AES256CTR.java @@ -42,6 +42,7 @@ public class AES256CTR /** Named factory for AES256CBC Cipher */ public static class Factory implements net.schmizz.sshj.common.Factory.Named { + @Override public Cipher create() { return new AES256CTR(); diff --git a/src/main/java/net/schmizz/sshj/transport/cipher/BlowfishCBC.java b/src/main/java/net/schmizz/sshj/transport/cipher/BlowfishCBC.java index adcc5b7a..90076956 100644 --- a/src/main/java/net/schmizz/sshj/transport/cipher/BlowfishCBC.java +++ b/src/main/java/net/schmizz/sshj/transport/cipher/BlowfishCBC.java @@ -42,6 +42,7 @@ public class BlowfishCBC /** Named factory for BlowfishCBC Cipher */ public static class Factory implements net.schmizz.sshj.common.Factory.Named { + @Override public Cipher create() { return new BlowfishCBC(); diff --git a/src/main/java/net/schmizz/sshj/transport/cipher/NoneCipher.java b/src/main/java/net/schmizz/sshj/transport/cipher/NoneCipher.java index f9508a74..374a50af 100644 --- a/src/main/java/net/schmizz/sshj/transport/cipher/NoneCipher.java +++ b/src/main/java/net/schmizz/sshj/transport/cipher/NoneCipher.java @@ -42,6 +42,7 @@ public class NoneCipher /** Named factory for the no-op Cipher */ public static class Factory implements net.schmizz.sshj.common.Factory.Named { + @Override public Cipher create() { return new NoneCipher(); diff --git a/src/main/java/net/schmizz/sshj/transport/cipher/TripleDESCBC.java b/src/main/java/net/schmizz/sshj/transport/cipher/TripleDESCBC.java index 83122717..a1b9aa0a 100644 --- a/src/main/java/net/schmizz/sshj/transport/cipher/TripleDESCBC.java +++ b/src/main/java/net/schmizz/sshj/transport/cipher/TripleDESCBC.java @@ -42,6 +42,7 @@ public class TripleDESCBC /** Named factory for TripleDESCBC Cipher */ public static class Factory implements net.schmizz.sshj.common.Factory.Named { + @Override public Cipher create() { return new TripleDESCBC(); diff --git a/src/main/java/net/schmizz/sshj/transport/compression/DelayedZlibCompression.java b/src/main/java/net/schmizz/sshj/transport/compression/DelayedZlibCompression.java index c4ff1b02..c8d1eb75 100644 --- a/src/main/java/net/schmizz/sshj/transport/compression/DelayedZlibCompression.java +++ b/src/main/java/net/schmizz/sshj/transport/compression/DelayedZlibCompression.java @@ -46,6 +46,7 @@ public class DelayedZlibCompression /** Named factory for the ZLib Delayed Compression. */ public static class Factory implements net.schmizz.sshj.common.Factory.Named { + @Override public Compression create() { return new DelayedZlibCompression(); diff --git a/src/main/java/net/schmizz/sshj/transport/compression/NoneCompression.java b/src/main/java/net/schmizz/sshj/transport/compression/NoneCompression.java index cc6e9f20..4c4ef99d 100644 --- a/src/main/java/net/schmizz/sshj/transport/compression/NoneCompression.java +++ b/src/main/java/net/schmizz/sshj/transport/compression/NoneCompression.java @@ -42,6 +42,7 @@ public abstract class NoneCompression /** Named factory for the no-op Compression */ public static class Factory implements net.schmizz.sshj.common.Factory.Named { + @Override public Compression create() { return null; diff --git a/src/main/java/net/schmizz/sshj/transport/compression/ZlibCompression.java b/src/main/java/net/schmizz/sshj/transport/compression/ZlibCompression.java index e02721e7..7e6197f8 100644 --- a/src/main/java/net/schmizz/sshj/transport/compression/ZlibCompression.java +++ b/src/main/java/net/schmizz/sshj/transport/compression/ZlibCompression.java @@ -49,6 +49,7 @@ public class ZlibCompression /** Named factory for the ZLib Compression. */ public static class Factory implements net.schmizz.sshj.common.Factory.Named { + @Override public Compression create() { return new ZlibCompression(); @@ -125,7 +126,7 @@ public class ZlibCompression return; default: throw new TransportException(DisconnectReason.COMPRESSION_ERROR, "uncompress: inflate returned " - + status); + + status); } } } diff --git a/src/main/java/net/schmizz/sshj/transport/kex/DHG14.java b/src/main/java/net/schmizz/sshj/transport/kex/DHG14.java index 5ddab369..a86a6460 100644 --- a/src/main/java/net/schmizz/sshj/transport/kex/DHG14.java +++ b/src/main/java/net/schmizz/sshj/transport/kex/DHG14.java @@ -63,7 +63,8 @@ public class DHG14 } @Override - protected void initDH(DH dh) throws GeneralSecurityException { + protected void initDH(DH dh) + throws GeneralSecurityException { dh.init(DHGroupData.P14, DHGroupData.G); } diff --git a/src/main/java/net/schmizz/sshj/transport/kex/DHGroupData.java b/src/main/java/net/schmizz/sshj/transport/kex/DHGroupData.java index aa7fe35d..c51b2a5d 100644 --- a/src/main/java/net/schmizz/sshj/transport/kex/DHGroupData.java +++ b/src/main/java/net/schmizz/sshj/transport/kex/DHGroupData.java @@ -45,18 +45,18 @@ public final class DHGroupData { public static final BigInteger P1 = new BigInteger("1797693134862315907708391567937874531978602960487560117064444236841971802161585193" + - "6894783379586492554150218056548598050364644054819923910005079287700335581663922955" + - "3136239076508735759914822574862575007425302077447712589550957937778424442426617334" + - "727629299387668709205606050270810842907692932019128194467627007"); + "6894783379586492554150218056548598050364644054819923910005079287700335581663922955" + + "3136239076508735759914822574862575007425302077447712589550957937778424442426617334" + + "727629299387668709205606050270810842907692932019128194467627007"); public static final BigInteger P14 = new BigInteger("3231700607131100730033891392642382824881794124114023911284200975140074170663435422" + - "2619689417363569347117901737909704191754605873209195028853758986185622153212175412" + - "5149017745202702357960782362488842461894775876411059286460994117232454266225221932" + - "3054091903768052423551912567971587011700105805587765103886184728025797605490356973" + - "2561526167081339361799541336476559160368317896729073178384589680639671900977202194" + - "1686472258710314113364293195361934716365332097170774482279885885653692086452966360" + - "7725026895550592836275112117409697299806841055435958486658329164213621823107899099" + - "9448652468262416972035911852507045361090559"); + "2619689417363569347117901737909704191754605873209195028853758986185622153212175412" + + "5149017745202702357960782362488842461894775876411059286460994117232454266225221932" + + "3054091903768052423551912567971587011700105805587765103886184728025797605490356973" + + "2561526167081339361799541336476559160368317896729073178384589680639671900977202194" + + "1686472258710314113364293195361934716365332097170774482279885885653692086452966360" + + "7725026895550592836275112117409697299806841055435958486658329164213621823107899099" + + "9448652468262416972035911852507045361090559"); } diff --git a/src/main/java/net/schmizz/sshj/transport/random/SingletonRandomFactory.java b/src/main/java/net/schmizz/sshj/transport/random/SingletonRandomFactory.java index 1dac8b45..e92107c9 100644 --- a/src/main/java/net/schmizz/sshj/transport/random/SingletonRandomFactory.java +++ b/src/main/java/net/schmizz/sshj/transport/random/SingletonRandomFactory.java @@ -40,6 +40,7 @@ import net.schmizz.sshj.common.Factory; /** A random factory wrapper that uses a single random instance. The underlying random instance has to be thread safe. */ public class SingletonRandomFactory implements Random, Factory { + private final Random random; public SingletonRandomFactory(Factory factory) { diff --git a/src/main/java/net/schmizz/sshj/transport/verification/ConsoleKnownHostsVerifier.java b/src/main/java/net/schmizz/sshj/transport/verification/ConsoleKnownHostsVerifier.java index 152ba97c..0eb9bcad 100644 --- a/src/main/java/net/schmizz/sshj/transport/verification/ConsoleKnownHostsVerifier.java +++ b/src/main/java/net/schmizz/sshj/transport/verification/ConsoleKnownHostsVerifier.java @@ -41,7 +41,7 @@ public class ConsoleKnownHostsVerifier protected boolean hostKeyUnverifiableAction(String hostname, PublicKey key) { final KeyType type = KeyType.fromKey(key); console.printf("The authenticity of host '%s' can't be established.\n" + - "%s key fingerprint is %s.\n", hostname, type, SecurityUtils.getFingerprint(key)); + "%s key fingerprint is %s.\n", hostname, type, SecurityUtils.getFingerprint(key)); String response = console.readLine("Are you sure you want to continue connecting (yes/no)? "); while (!(response.equalsIgnoreCase(YES) || response.equalsIgnoreCase(NO))) { response = console.readLine("Please explicitly enter yes/no: "); @@ -66,15 +66,15 @@ public class ConsoleKnownHostsVerifier final String path = getFile().getAbsolutePath(); console.printf( "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n" + - "@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @\n" + - "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n" + - "IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!\n" + - "Someone could be eavesdropping on you right now (man-in-the-middle attack)!\n" + - "It is also possible that the host key has just been changed.\n" + - "The fingerprint for the %s key sent by the remote host is\n" + - "%s.\n" + - "Please contact your system administrator or" + - "add correct host key in %s to get rid of this message.\n", + "@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @\n" + + "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n" + + "IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!\n" + + "Someone could be eavesdropping on you right now (man-in-the-middle attack)!\n" + + "It is also possible that the host key has just been changed.\n" + + "The fingerprint for the %s key sent by the remote host is\n" + + "%s.\n" + + "Please contact your system administrator or" + + "add correct host key in %s to get rid of this message.\n", type, fp, path); return false; } diff --git a/src/main/java/net/schmizz/sshj/userauth/UserAuthImpl.java b/src/main/java/net/schmizz/sshj/userauth/UserAuthImpl.java index 2dd21bb3..07b5fdc4 100644 --- a/src/main/java/net/schmizz/sshj/userauth/UserAuthImpl.java +++ b/src/main/java/net/schmizz/sshj/userauth/UserAuthImpl.java @@ -139,11 +139,13 @@ public class UserAuthImpl case USERAUTH_BANNER: { banner = buf.readString(); - } break; + } + break; case USERAUTH_SUCCESS: { authenticated.set(); - } break; + } + break; case USERAUTH_FAILURE: { allowedMethods.clear(); @@ -154,7 +156,8 @@ public class UserAuthImpl } else { authenticated.deliverError(new UserAuthException(currentMethod.getName() + " auth failed")); } - } break; + } + break; default: { log.debug("Asking `{}` method to handle {} packet", currentMethod.getName(), msg); diff --git a/src/main/java/net/schmizz/sshj/userauth/keyprovider/KeyProviderUtil.java b/src/main/java/net/schmizz/sshj/userauth/keyprovider/KeyProviderUtil.java index 3ece9411..2ca49077 100644 --- a/src/main/java/net/schmizz/sshj/userauth/keyprovider/KeyProviderUtil.java +++ b/src/main/java/net/schmizz/sshj/userauth/keyprovider/KeyProviderUtil.java @@ -75,7 +75,7 @@ public class KeyProviderUtil { */ private static FileKeyProvider.Format detectKeyFileFormat(Reader privateKey, boolean separatePubKey) - throws IOException { + throws IOException { BufferedReader br = new BufferedReader(privateKey); String firstLine = br.readLine(); IOUtils.closeQuietly(br); diff --git a/src/main/java/net/schmizz/sshj/userauth/keyprovider/OpenSSHKeyFile.java b/src/main/java/net/schmizz/sshj/userauth/keyprovider/OpenSSHKeyFile.java index cd18aa1e..a22bfc56 100644 --- a/src/main/java/net/schmizz/sshj/userauth/keyprovider/OpenSSHKeyFile.java +++ b/src/main/java/net/schmizz/sshj/userauth/keyprovider/OpenSSHKeyFile.java @@ -83,7 +83,7 @@ public class OpenSSHKeyFile /** * Read and store the separate public key provided alongside the private key - * + * * @param publicKey Public key accessible through a {@code Reader} */ private void initPubKey(Reader publicKey) { diff --git a/src/main/java/net/schmizz/sshj/userauth/keyprovider/PKCS8KeyFile.java b/src/main/java/net/schmizz/sshj/userauth/keyprovider/PKCS8KeyFile.java index b34758bf..9316af19 100644 --- a/src/main/java/net/schmizz/sshj/userauth/keyprovider/PKCS8KeyFile.java +++ b/src/main/java/net/schmizz/sshj/userauth/keyprovider/PKCS8KeyFile.java @@ -22,18 +22,13 @@ import net.schmizz.sshj.userauth.password.PasswordUtils; import net.schmizz.sshj.userauth.password.PrivateKeyFileResource; import net.schmizz.sshj.userauth.password.PrivateKeyStringResource; import net.schmizz.sshj.userauth.password.Resource; - import org.bouncycastle.openssl.EncryptionException; import org.bouncycastle.openssl.PEMReader; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.File; -import java.io.FileInputStream; import java.io.IOException; -import java.io.InputStreamReader; -import java.io.Reader; -import java.io.StringReader; import java.security.KeyPair; import java.security.PrivateKey; import java.security.PublicKey; @@ -44,6 +39,7 @@ public class PKCS8KeyFile public static class Factory implements net.schmizz.sshj.common.Factory.Named { + @Override public FileKeyProvider create() { return new PKCS8KeyFile(); @@ -127,7 +123,7 @@ public class PKCS8KeyFile PEMReader r = null; Object o = null; try { - for (; ;) { + for (; ; ) { // while the PasswordFinder tells us we should retry try { r = new PEMReader(resource.getReader(), pFinder); diff --git a/src/main/java/net/schmizz/sshj/userauth/method/AuthKeyboardInteractive.java b/src/main/java/net/schmizz/sshj/userauth/method/AuthKeyboardInteractive.java index 4a0e5b74..4054f13e 100644 --- a/src/main/java/net/schmizz/sshj/userauth/method/AuthKeyboardInteractive.java +++ b/src/main/java/net/schmizz/sshj/userauth/method/AuthKeyboardInteractive.java @@ -51,6 +51,7 @@ public class AuthKeyboardInteractive } private static class CharArrWrap { + private final char[] arr; private CharArrWrap(char[] arr) { diff --git a/src/main/java/net/schmizz/sshj/userauth/method/KeyedAuthMethod.java b/src/main/java/net/schmizz/sshj/userauth/method/KeyedAuthMethod.java index 8106e226..ebc10b0c 100644 --- a/src/main/java/net/schmizz/sshj/userauth/method/KeyedAuthMethod.java +++ b/src/main/java/net/schmizz/sshj/userauth/method/KeyedAuthMethod.java @@ -48,7 +48,7 @@ public abstract class KeyedAuthMethod // public key as 2 strings: [ key type | key blob ] reqBuf.putString(KeyType.fromKey(key).toString()) - .putString(new Buffer.PlainBuffer().putPublicKey(key).getCompactData()); + .putString(new Buffer.PlainBuffer().putPublicKey(key).getCompactData()); return reqBuf; } @@ -67,9 +67,10 @@ public abstract class KeyedAuthMethod throw new UserAuthException("Could not create signature instance for " + kt + " key"); sigger.init(null, key); - sigger.update(new Buffer.PlainBuffer().putString(params.getTransport().getSessionID()) // - .putBuffer(reqBuf) // & rest of the data for sig - .getCompactData()); + sigger.update(new Buffer.PlainBuffer() + .putString(params.getTransport().getSessionID()) + .putBuffer(reqBuf) // & rest of the data for sig + .getCompactData()); reqBuf.putSignature(kt, sigger.sign()); return reqBuf; } diff --git a/src/main/java/net/schmizz/sshj/userauth/password/AccountResource.java b/src/main/java/net/schmizz/sshj/userauth/password/AccountResource.java index 82620896..5e5e9690 100644 --- a/src/main/java/net/schmizz/sshj/userauth/password/AccountResource.java +++ b/src/main/java/net/schmizz/sshj/userauth/password/AccountResource.java @@ -27,7 +27,8 @@ public class AccountResource } @Override - public Reader getReader() throws IOException { + public Reader getReader() + throws IOException { return new StringReader(getDetail()); } } diff --git a/src/main/java/net/schmizz/sshj/userauth/password/PrivateKeyStringResource.java b/src/main/java/net/schmizz/sshj/userauth/password/PrivateKeyStringResource.java index a727aebb..c2597ba3 100644 --- a/src/main/java/net/schmizz/sshj/userauth/password/PrivateKeyStringResource.java +++ b/src/main/java/net/schmizz/sshj/userauth/password/PrivateKeyStringResource.java @@ -19,14 +19,16 @@ import java.io.IOException; import java.io.Reader; import java.io.StringReader; -public class PrivateKeyStringResource extends Resource { +public class PrivateKeyStringResource + extends Resource { public PrivateKeyStringResource(String string) { super(string); } @Override - public Reader getReader() throws IOException { + public Reader getReader() + throws IOException { return new StringReader(getDetail()); } diff --git a/src/main/java/net/schmizz/sshj/xfer/FileSystemFile.java b/src/main/java/net/schmizz/sshj/xfer/FileSystemFile.java index ca1c81ea..c4c5d23a 100644 --- a/src/main/java/net/schmizz/sshj/xfer/FileSystemFile.java +++ b/src/main/java/net/schmizz/sshj/xfer/FileSystemFile.java @@ -26,9 +26,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; -import java.util.Map; public class FileSystemFile implements LocalSourceFile, LocalDestFile { diff --git a/src/main/java/net/schmizz/sshj/xfer/FileTransfer.java b/src/main/java/net/schmizz/sshj/xfer/FileTransfer.java index 61d4e2cb..f0645503 100644 --- a/src/main/java/net/schmizz/sshj/xfer/FileTransfer.java +++ b/src/main/java/net/schmizz/sshj/xfer/FileTransfer.java @@ -26,7 +26,7 @@ public interface FileTransfer { throws IOException; void upload(LocalSourceFile localFile, String remotePath) - throws IOException; + throws IOException; void download(String remotePath, LocalDestFile localFile) throws IOException; diff --git a/src/main/java/net/schmizz/sshj/xfer/LocalSourceFile.java b/src/main/java/net/schmizz/sshj/xfer/LocalSourceFile.java index 9078a4ae..278248b0 100644 --- a/src/main/java/net/schmizz/sshj/xfer/LocalSourceFile.java +++ b/src/main/java/net/schmizz/sshj/xfer/LocalSourceFile.java @@ -34,7 +34,8 @@ public interface LocalSourceFile { * * @throws IOException */ - int getPermissions() throws IOException; + int getPermissions() + throws IOException; boolean isFile(); diff --git a/src/main/java/net/schmizz/sshj/xfer/scp/SCPException.java b/src/main/java/net/schmizz/sshj/xfer/scp/SCPException.java index d98c3ca4..61818519 100644 --- a/src/main/java/net/schmizz/sshj/xfer/scp/SCPException.java +++ b/src/main/java/net/schmizz/sshj/xfer/scp/SCPException.java @@ -19,6 +19,7 @@ import net.schmizz.sshj.common.SSHException; public class SCPException extends SSHException { + public SCPException(String message) { super(message); } diff --git a/src/main/java/net/schmizz/sshj/xfer/scp/SCPFileTransfer.java b/src/main/java/net/schmizz/sshj/xfer/scp/SCPFileTransfer.java index 17b1760e..b9cd4892 100644 --- a/src/main/java/net/schmizz/sshj/xfer/scp/SCPFileTransfer.java +++ b/src/main/java/net/schmizz/sshj/xfer/scp/SCPFileTransfer.java @@ -15,8 +15,6 @@ */ package net.schmizz.sshj.xfer.scp; -import java.io.IOException; - import net.schmizz.sshj.connection.channel.direct.SessionFactory; import net.schmizz.sshj.xfer.AbstractFileTransfer; import net.schmizz.sshj.xfer.FileSystemFile; @@ -24,6 +22,8 @@ import net.schmizz.sshj.xfer.FileTransfer; import net.schmizz.sshj.xfer.LocalDestFile; import net.schmizz.sshj.xfer.LocalSourceFile; +import java.io.IOException; + public class SCPFileTransfer extends AbstractFileTransfer implements FileTransfer { @@ -43,7 +43,7 @@ public class SCPFileTransfer } private SCPEngine newSCPEngine() { - return new SCPEngine(sessionFactory, getTransferListener()); + return new SCPEngine(sessionFactory, getTransferListener()); } @Override @@ -65,9 +65,9 @@ public class SCPFileTransfer } @Override - public void upload(LocalSourceFile localFile, String remotePath) - throws IOException { - newSCPUploadClient().copy(localFile, remotePath); - } + public void upload(LocalSourceFile localFile, String remotePath) + throws IOException { + newSCPUploadClient().copy(localFile, remotePath); + } } diff --git a/src/test/java/net/schmizz/sshj/SmokeTest.java b/src/test/java/net/schmizz/sshj/SmokeTest.java index d6d38165..8e28e912 100644 --- a/src/test/java/net/schmizz/sshj/SmokeTest.java +++ b/src/test/java/net/schmizz/sshj/SmokeTest.java @@ -50,7 +50,8 @@ public class SmokeTest { } @Test - public void authenticated() throws UserAuthException, TransportException { + public void authenticated() + throws UserAuthException, TransportException { fixture.dummyAuth(); assertTrue(fixture.getClient().isAuthenticated()); } diff --git a/src/test/java/net/schmizz/sshj/keyprovider/OpenSSHKeyFileTest.java b/src/test/java/net/schmizz/sshj/keyprovider/OpenSSHKeyFileTest.java index 144059d7..394d44cc 100644 --- a/src/test/java/net/schmizz/sshj/keyprovider/OpenSSHKeyFileTest.java +++ b/src/test/java/net/schmizz/sshj/keyprovider/OpenSSHKeyFileTest.java @@ -116,7 +116,7 @@ public class OpenSSHKeyFileTest { @Test public void fromString() - throws IOException, GeneralSecurityException { + throws IOException, GeneralSecurityException { FileKeyProvider dsa = new OpenSSHKeyFile(); String privateKey = readFile("src/test/resources/id_dsa"); String publicKey = readFile("src/test/resources/id_dsa.pub"); @@ -136,12 +136,11 @@ public class OpenSSHKeyFileTest { private String readFile(String pathname) throws IOException { - StringBuilder fileContents = new StringBuilder(); Scanner scanner = new Scanner(new File(pathname)); String lineSeparator = System.getProperty("line.separator"); try { - while(scanner.hasNextLine()) { + while (scanner.hasNextLine()) { fileContents.append(scanner.nextLine() + lineSeparator); } return fileContents.toString(); diff --git a/src/test/java/net/schmizz/sshj/util/BufferTest.java b/src/test/java/net/schmizz/sshj/util/BufferTest.java index bb12b83a..bbed05ee 100644 --- a/src/test/java/net/schmizz/sshj/util/BufferTest.java +++ b/src/test/java/net/schmizz/sshj/util/BufferTest.java @@ -28,6 +28,7 @@ import static org.junit.Assert.assertEquals; /** Tests {@link Buffer} functionality */ public class BufferTest { + private Buffer.PlainBuffer posBuf; private Buffer.PlainBuffer handyBuf; diff --git a/src/test/java/net/schmizz/sshj/util/KeyUtil.java b/src/test/java/net/schmizz/sshj/util/KeyUtil.java index a20836c0..683c477b 100644 --- a/src/test/java/net/schmizz/sshj/util/KeyUtil.java +++ b/src/test/java/net/schmizz/sshj/util/KeyUtil.java @@ -29,34 +29,38 @@ import java.security.spec.RSAPublicKeySpec; public class KeyUtil { /** Creates a DSA private key. */ - public static PrivateKey newDSAPrivateKey(String x, String p, String q, String g) throws GeneralSecurityException { - return SecurityUtils.getKeyFactory("DSA").generatePrivate(new DSAPrivateKeySpec // - (new BigInteger(x, 16), // - new BigInteger(p, 16), // - new BigInteger(q, 16), // - new BigInteger(g, 16))); + public static PrivateKey newDSAPrivateKey(String x, String p, String q, String g) + throws GeneralSecurityException { + return SecurityUtils.getKeyFactory("DSA").generatePrivate(new DSAPrivateKeySpec(new BigInteger(x, 16), + new BigInteger(p, 16), + new BigInteger(q, 16), + new BigInteger(g, 16)) + ); } /** Creates a DSA public key. */ - public static PublicKey newDSAPublicKey(String y, String p, String q, String g) throws GeneralSecurityException { - return SecurityUtils.getKeyFactory("DSA").generatePublic(new DSAPublicKeySpec // - (new BigInteger(y, 16), // - new BigInteger(p, 16), // - new BigInteger(q, 16), // - new BigInteger(g, 16))); + public static PublicKey newDSAPublicKey(String y, String p, String q, String g) + throws GeneralSecurityException { + return SecurityUtils.getKeyFactory("DSA").generatePublic(new DSAPublicKeySpec(new BigInteger(y, 16), + new BigInteger(p, 16), + new BigInteger(q, 16), + new BigInteger(g, 16)) + ); } /** Creates an RSA private key. */ - public static PrivateKey newRSAPrivateKey(String modulus, String exponent) throws GeneralSecurityException { - return SecurityUtils.getKeyFactory("RSA").generatePrivate(new RSAPrivateKeySpec // - (new BigInteger(modulus, 16), // - new BigInteger(exponent, 16))); + public static PrivateKey newRSAPrivateKey(String modulus, String exponent) + throws GeneralSecurityException { + return SecurityUtils.getKeyFactory("RSA").generatePrivate(new RSAPrivateKeySpec(new BigInteger(modulus, 16), + new BigInteger(exponent, 16)) + ); } /** Creates an RSA public key. */ - public static PublicKey newRSAPublicKey(String modulus, String exponent) throws GeneralSecurityException { - return SecurityUtils.getKeyFactory("RSA").generatePublic(new RSAPublicKeySpec // - (new BigInteger(modulus, 16), new BigInteger(exponent, 16))); + public static PublicKey newRSAPublicKey(String modulus, String exponent) + throws GeneralSecurityException { + return SecurityUtils.getKeyFactory("RSA").generatePublic(new RSAPublicKeySpec(new BigInteger(modulus, 16), + new BigInteger(exponent, 16))); } }