diff --git a/java-scpclient/src/main/java/cz/it4i/fiji/scpclient/IdentityFile.java b/java-scpclient/src/main/java/cz/it4i/fiji/scpclient/IdentityFile.java index 7d7e65a1b016100d6bce3c5874faceac992771fb..8b46514ea6c0f0e1331bf1bd4cfc7371157fc3a4 100644 --- a/java-scpclient/src/main/java/cz/it4i/fiji/scpclient/IdentityFile.java +++ b/java-scpclient/src/main/java/cz/it4i/fiji/scpclient/IdentityFile.java @@ -12,17 +12,15 @@ class IdentityFile implements Identity { static IdentityFile newInstance(String prvfile, String pubfile, JSch jsch) throws JSchException { KeyPair kpair = KeyPair.load(jsch, prvfile, pubfile); - return new IdentityFile(jsch, prvfile, kpair); + return new IdentityFile(prvfile, kpair); } static IdentityFile newInstance(String name, byte[] prvkey, byte[] pubkey, JSch jsch) throws JSchException { - KeyPair kpair = KeyPair.load(jsch, prvkey, pubkey); - return new IdentityFile(jsch, name, kpair); + return new IdentityFile(name, kpair); } - private IdentityFile(JSch jsch, String name, KeyPair kpair) throws JSchException { - + private IdentityFile(String name, KeyPair kpair) { this.identity = name; this.kpair = kpair; } @@ -35,6 +33,7 @@ class IdentityFile implements Identity { * @return <tt>true</tt> if the decryption is succeeded or this identity is not * cyphered. */ + @Override public boolean setPassphrase(byte[] passphrase) throws JSchException { return kpair.decrypt(passphrase); } @@ -44,6 +43,7 @@ class IdentityFile implements Identity { * * @return the public-key blob */ + @Override public byte[] getPublicKeyBlob() { return kpair.getPublicKeyBlob(); } @@ -55,6 +55,7 @@ class IdentityFile implements Identity { * data to be signed * @return the signature */ + @Override public byte[] getSignature(byte[] data) { return kpair.getSignature(data); } @@ -63,6 +64,8 @@ class IdentityFile implements Identity { * @deprecated This method should not be invoked. * @see #setPassphrase(byte[] passphrase) */ + @Deprecated + @Override public boolean decrypt() { throw new RuntimeException("not implemented"); } @@ -72,6 +75,7 @@ class IdentityFile implements Identity { * * @return "ssh-rsa" or "ssh-dss" */ + @Override public String getAlgName() { if (kpair.getKeyType() == KeyPair.RSA) { return "ssh-rsa"; @@ -85,6 +89,7 @@ class IdentityFile implements Identity { * Returns the name of this identity. It will be useful to identify this object * in the {@link IdentityRepository}. */ + @Override public String getName() { return identity; } @@ -94,6 +99,7 @@ class IdentityFile implements Identity { * * @return <tt>true</tt> if this identity is cyphered. */ + @Override public boolean isEncrypted() { return kpair.isEncrypted(); } @@ -101,6 +107,7 @@ class IdentityFile implements Identity { /** * Disposes internally allocated data, like byte array for the private key. */ + @Override public void clear() { kpair.dispose(); kpair = null; diff --git a/java-scpclient/src/main/java/cz/it4i/fiji/scpclient/ScpClient.java b/java-scpclient/src/main/java/cz/it4i/fiji/scpclient/ScpClient.java index bd3b9b5ac4d0b54f77d341895c4a1b356c5bf7d8..dc666bc7199d86d29792c2d5d1328f5e719f00e1 100644 --- a/java-scpclient/src/main/java/cz/it4i/fiji/scpclient/ScpClient.java +++ b/java-scpclient/src/main/java/cz/it4i/fiji/scpclient/ScpClient.java @@ -70,9 +70,9 @@ public class ScpClient implements Closeable { init(hostName, userName, id); } - private void init(String hostName, String username, Identity privateKeyFile) throws JSchException { - this.hostName = hostName; - this.username = username; + private void init(String initHostName, String initUsername, Identity privateKeyFile) throws JSchException { + this.hostName = initHostName; + this.username = initUsername; jsch.addIdentity(privateKeyFile, null); } @@ -91,11 +91,9 @@ public class ScpClient implements Closeable { public boolean download(String lfile, OutputStream os, TransferFileProgress progress) throws JSchException, IOException { - Session session = getConnectedSession(); - - // exec 'scp -f rfile' remotely + // exec 'scp -f rfile' remotely String command = "scp -f " + lfile; - Channel channel = session.openChannel("exec"); + Channel channel = getConnectedSession().openChannel("exec"); try { ((ChannelExec) channel).setCommand(command); @@ -200,11 +198,10 @@ public class ScpClient implements Closeable { public boolean upload(InputStream is, String fileName, long length, long lastModified, TransferFileProgress progress) throws JSchException, IOException { - Session session = getConnectedSession(); boolean ptimestamp = true; // exec 'scp -t rfile' remotely String command = "scp " + (ptimestamp ? "-p" : "") + " -t " + fileName; - Channel channel = session.openChannel("exec"); + Channel channel = getConnectedSession().openChannel("exec"); ((ChannelExec) channel).setCommand(command); // get I/O streams for remote scp try (OutputStream out = channel.getOutputStream(); InputStream in = channel.getInputStream()) { @@ -263,11 +260,9 @@ public class ScpClient implements Closeable { } public long size(String lfile) throws JSchException, IOException { - Session session = getConnectedSession(); - // exec 'scp -f rfile' remotely String command = "scp -f " + lfile; - Channel channel = session.openChannel("exec"); + Channel channel = getConnectedSession().openChannel("exec"); try { ((ChannelExec) channel).setCommand(command); @@ -315,11 +310,10 @@ public class ScpClient implements Closeable { } @SuppressWarnings("unchecked") - public List<Long> sizeByLs(String lfile) throws JSchException, IOException { - Session session = getConnectedSession(); - + public List<Long> sizeByLs(String lfile) throws JSchException{ + // exec 'scp -f rfile' remotely - Channel channel = session.openChannel("sftp"); + Channel channel = getConnectedSession().openChannel("sftp"); try { channel.connect();