diff --git a/src/main/java/net/schmizz/sshj/transport/TransportImpl.java b/src/main/java/net/schmizz/sshj/transport/TransportImpl.java index 0ea1ea845..6d2073d72 100644 --- a/src/main/java/net/schmizz/sshj/transport/TransportImpl.java +++ b/src/main/java/net/schmizz/sshj/transport/TransportImpl.java @@ -223,43 +223,6 @@ private String readIdentification(Buffer.PlainBuffer buffer) if (ident.isEmpty()) { return ident; } -// -// byte[] data = new byte[256]; -// for (; ; ) { -// int savedBufPos = buffer.rpos(); -// int pos = 0; -// boolean needLF = false; -// for (; ; ) { -// if (buffer.available() == 0) { -// // Need more data, so undo reading and return null -// buffer.rpos(savedBufPos); -// return ""; -// } -// byte b = buffer.readByte(); -// if (b == '\r') { -// needLF = true; -// continue; -// } -// if (b == '\n') -// break; -// if (needLF) { -// log.error("Incorrect identification, was expecting a '\n' after the '\r', got: '{}' (hex: {})", b, Integer.toHexString(b & 0xFF)); -// log.error("Data received up til here was: {}", new String(data, 0, pos)); -// throw new TransportException("Incorrect identification: bad line ending: " + ByteArrayUtils.toHex(data, 0, pos)); -// } -// if (pos >= data.length) { -// log.error("Incorrect identification String received, line was longer than expected: {}", new String(data, 0, pos)); -// log.error("Just for good measure, bytes were: {}", ByteArrayUtils.printHex(data, 0, pos)); -// throw new TransportException("Incorrect identification: line too long: " + ByteArrayUtils.printHex(data, 0, pos)); -// } -// data[pos++] = b; -// } -// ident = new String(data, 0, pos); -// if (ident.startsWith("SSH-")) -// break; -// if (buffer.rpos() > 16 * 1024) -// throw new TransportException("Incorrect identification: too many header lines"); -// } if (!ident.startsWith("SSH-2.0-") && !ident.startsWith("SSH-1.99-")) throw new TransportException(DisconnectReason.PROTOCOL_VERSION_NOT_SUPPORTED, diff --git a/src/main/java/net/schmizz/sshj/transport/digest/SHA384.java b/src/main/java/net/schmizz/sshj/transport/digest/SHA384.java index 883f82d36..52d1253b8 100644 --- a/src/main/java/net/schmizz/sshj/transport/digest/SHA384.java +++ b/src/main/java/net/schmizz/sshj/transport/digest/SHA384.java @@ -16,22 +16,26 @@ package net.schmizz.sshj.transport.digest; public class SHA384 extends BaseDigest { -/** Named factory for SHA384 digest */ -public static class Factory - implements net.schmizz.sshj.common.Factory.Named { + /** + * Named factory for SHA384 digest + */ + public static class Factory + implements net.schmizz.sshj.common.Factory.Named { - @Override - public Digest create() { - return new SHA384(); - } + @Override + public Digest create() { + return new SHA384(); + } - @Override - public String getName() { - return "sha384"; + @Override + public String getName() { + return "sha384"; + } } -} - /** Create a new instance of a SHA384 digest */ + /** + * Create a new instance of a SHA384 digest + */ public SHA384() { super("SHA-384", 48); } diff --git a/src/main/java/net/schmizz/sshj/transport/digest/SHA512.java b/src/main/java/net/schmizz/sshj/transport/digest/SHA512.java index 976726aa6..1e152a8ab 100644 --- a/src/main/java/net/schmizz/sshj/transport/digest/SHA512.java +++ b/src/main/java/net/schmizz/sshj/transport/digest/SHA512.java @@ -16,22 +16,26 @@ package net.schmizz.sshj.transport.digest; public class SHA512 extends BaseDigest { -/** Named factory for SHA384 digest */ -public static class Factory - implements net.schmizz.sshj.common.Factory.Named { + /** + * Named factory for SHA384 digest + */ + public static class Factory + implements net.schmizz.sshj.common.Factory.Named { - @Override - public Digest create() { - return new SHA512(); - } + @Override + public Digest create() { + return new SHA512(); + } - @Override - public String getName() { - return "sha512"; + @Override + public String getName() { + return "sha512"; + } } -} - /** Create a new instance of a SHA384 digest */ + /** + * Create a new instance of a SHA384 digest + */ public SHA512() { super("SHA-512", 64); } diff --git a/src/main/java/net/schmizz/sshj/userauth/keyprovider/PKCS5KeyFile.java b/src/main/java/net/schmizz/sshj/userauth/keyprovider/PKCS5KeyFile.java index 8f31ca7ed..ff14c3f07 100644 --- a/src/main/java/net/schmizz/sshj/userauth/keyprovider/PKCS5KeyFile.java +++ b/src/main/java/net/schmizz/sshj/userauth/keyprovider/PKCS5KeyFile.java @@ -32,7 +32,9 @@ import java.security.spec.*; import java.util.Arrays; -/** Represents a PKCS5-encoded key file. This is the format typically used by OpenSSH, OpenSSL, Amazon, etc. */ +/** + * Represents a PKCS5-encoded key file. This is the format typically used by OpenSSH, OpenSSL, Amazon, etc. + */ public class PKCS5KeyFile implements FileKeyProvider { @@ -171,7 +173,7 @@ protected KeyPair readKeyPair() if (ptr == -1) { throw new FormatException("Unrecognized DEK-Info: " + line.substring(10)); } else { - String algorithm = line.substring(10,ptr); + String algorithm = line.substring(10, ptr); if ("DES-EDE3-CBC".equals(algorithm)) { cipher = new TripleDESCBC(); } else if ("AES-128-CBC".equals(algorithm)) { @@ -183,7 +185,7 @@ protected KeyPair readKeyPair() } else { throw new FormatException("Not a supported algorithm: " + algorithm); } - iv = Arrays.copyOfRange(DatatypeConverter.parseHexBinary(line.substring(ptr+1)), 0, cipher.getIVSize()); + iv = Arrays.copyOfRange(DatatypeConverter.parseHexBinary(line.substring(ptr + 1)), 0, cipher.getIVSize()); } } else if (line.length() > 0) { sb.append(line); @@ -239,7 +241,7 @@ private byte[] getPassphraseBytes() { ByteBuffer bb = IOUtils.UTF8.encode(cb); byte[] result = Arrays.copyOfRange(bb.array(), bb.position(), bb.limit()); Arrays.fill(cb.array(), '\u0000'); - Arrays.fill(bb.array(), (byte)0); + Arrays.fill(bb.array(), (byte) 0); return result; } @@ -256,9 +258,9 @@ private byte[] decrypt(byte[] raw, Cipher cipher, byte[] iv) throws DecryptExcep byte[] hn = new byte[hnlen]; byte[] tmp = null; byte[] passphrase = getPassphraseBytes(); - for (int i=0; i + hsize <= hn.length;) { + for (int i = 0; i + hsize <= hn.length; ) { if (tmp != null) { - md5.update(tmp, 0, tmp.length); + md5.update(tmp, 0, tmp.length); } md5.update(passphrase, 0, passphrase.length); md5.update(iv, 0, iv.length > 8 ? 8 : iv.length); @@ -266,10 +268,10 @@ private byte[] decrypt(byte[] raw, Cipher cipher, byte[] iv) throws DecryptExcep System.arraycopy(tmp, 0, hn, i, tmp.length); i += tmp.length; } - Arrays.fill(passphrase, (byte)0); + Arrays.fill(passphrase, (byte) 0); byte[] key = Arrays.copyOfRange(hn, 0, bsize); cipher.init(Cipher.Mode.Decrypt, key, iv); - Arrays.fill(key, (byte)0); + Arrays.fill(key, (byte) 0); byte[] decrypted = Arrays.copyOf(raw, raw.length); cipher.update(decrypted, 0, decrypted.length); if (ASN1Data.MAGIC == decrypted[0]) { @@ -280,7 +282,7 @@ private byte[] decrypt(byte[] raw, Cipher cipher, byte[] iv) throws DecryptExcep } class ASN1Data { - static final byte MAGIC = (byte)0x30; + static final byte MAGIC = (byte) 0x30; private byte[] buff; private int index, length; diff --git a/src/test/java/net/schmizz/sshj/sftp/FileModeTest.java b/src/test/java/net/schmizz/sshj/sftp/FileModeTest.java index 2f90a9d3d..861a9f41c 100644 --- a/src/test/java/net/schmizz/sshj/sftp/FileModeTest.java +++ b/src/test/java/net/schmizz/sshj/sftp/FileModeTest.java @@ -22,17 +22,17 @@ public class FileModeTest { - @Test - public void shouldDetectDirectoryWithLinuxMask() { - FileMode fileMode = new FileMode(040755); - assertThat(fileMode.toString(), equalTo("[mask=40755]")); - assertThat(fileMode.getType(), equalTo(FileMode.Type.DIRECTORY)); - } + @Test + public void shouldDetectDirectoryWithLinuxMask() { + FileMode fileMode = new FileMode(040755); + assertThat(fileMode.toString(), equalTo("[mask=40755]")); + assertThat(fileMode.getType(), equalTo(FileMode.Type.DIRECTORY)); + } - @Test - public void shouldDetectDirectoryWithAixUnixMask() { - FileMode fileMode = new FileMode(0240755); - assertThat(fileMode.toString(), equalTo("[mask=240755]")); - assertThat(fileMode.getType(), equalTo(FileMode.Type.DIRECTORY)); - } + @Test + public void shouldDetectDirectoryWithAixUnixMask() { + FileMode fileMode = new FileMode(0240755); + assertThat(fileMode.toString(), equalTo("[mask=240755]")); + assertThat(fileMode.getType(), equalTo(FileMode.Type.DIRECTORY)); + } }