You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by co...@apache.org on 2019/07/02 10:09:01 UTC
[camel] branch master updated: Use StandardCharsets.UTF_8 in
camel-ftp
This is an automated email from the ASF dual-hosted git repository.
coheigea pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/master by this push:
new 2940459 Use StandardCharsets.UTF_8 in camel-ftp
2940459 is described below
commit 29404595676c6f78ec366fe797e307016e23993e
Author: Colm O hEigeartaigh <co...@apache.org>
AuthorDate: Tue Jul 2 11:08:41 2019 +0100
Use StandardCharsets.UTF_8 in camel-ftp
---
.../component/file/remote/DSAKeyPairIdentity.java | 5 ++---
.../component/file/remote/RSAKeyPairIdentity.java | 5 ++---
.../component/file/remote/SftpOperations.java | 23 ++++++++--------------
3 files changed, 12 insertions(+), 21 deletions(-)
diff --git a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/DSAKeyPairIdentity.java b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/DSAKeyPairIdentity.java
index abf2ba4..d95a2d1 100644
--- a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/DSAKeyPairIdentity.java
+++ b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/DSAKeyPairIdentity.java
@@ -102,8 +102,7 @@ public class DSAKeyPairIdentity implements Identity {
public byte[] getSignature(byte[] data) {
try {
PrivateKey prvKey = keyPair.getPrivate();
- Signature sig;
- sig = Signature.getInstance("SHA1withDSA");
+ Signature sig = Signature.getInstance("SHA1withDSA");
sig.initSign(prvKey);
sig.update(data);
byte[] sshDss = ALGORITHM_TYPE.getBytes();
@@ -147,7 +146,7 @@ public class DSAKeyPairIdentity implements Identity {
* Java (which uses a DER encoding of a signature)." [taken from <a href=
* "http://www.codeproject.com/Articles/25590/Cryptographic-Interoperability-Digital-Signatures"
* >Cryptographic Interoperability Digital Signatures</a>]
- *
+ *
* @param sig
* signature in DER format
* @return signature in P1363 format; SEQUENCE ::= { r INTEGER, s INTEGER }
diff --git a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RSAKeyPairIdentity.java b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RSAKeyPairIdentity.java
index b7f3ec5..f3af15a 100644
--- a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RSAKeyPairIdentity.java
+++ b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RSAKeyPairIdentity.java
@@ -35,7 +35,7 @@ import org.slf4j.LoggerFactory;
public class RSAKeyPairIdentity implements Identity {
private static final String ALGORITHM_TYPE = "ssh-rsa";
private final Logger log = LoggerFactory.getLogger(getClass());
-
+
private KeyPair keyPair;
private String name;
@@ -85,9 +85,8 @@ public class RSAKeyPairIdentity implements Identity {
@Override
public byte[] getSignature(byte[] data) {
PrivateKey prvKey = keyPair.getPrivate();
- Signature sig;
try {
- sig = Signature.getInstance("SHA1withRSA");
+ Signature sig = Signature.getInstance("SHA1withRSA");
sig.initSign(prvKey);
sig.update(data);
byte[] sshRsa = ALGORITHM_TYPE.getBytes();
diff --git a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpOperations.java b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpOperations.java
index e171b28..237110e 100644
--- a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpOperations.java
+++ b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpOperations.java
@@ -27,6 +27,7 @@ import java.io.UnsupportedEncodingException;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;
+import java.nio.charset.StandardCharsets;
import java.security.KeyPair;
import java.security.interfaces.DSAPrivateKey;
import java.security.interfaces.DSAPublicKey;
@@ -35,7 +36,6 @@ import java.security.interfaces.RSAPublicKey;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.List;
-import java.util.Vector;
import java.util.regex.Pattern;
import com.jcraft.jsch.ChannelSftp;
@@ -219,11 +219,7 @@ public class SftpOperations implements RemoteFileOperations<SftpRemoteFile> {
LOG.debug("Using private key information from byte array");
byte[] passphrase = null;
if (isNotEmpty(sftpConfig.getPrivateKeyPassphrase())) {
- try {
- passphrase = sftpConfig.getPrivateKeyPassphrase().getBytes("UTF-8");
- } catch (UnsupportedEncodingException e) {
- throw new JSchException("Cannot transform passphrase to byte[]", e);
- }
+ passphrase = sftpConfig.getPrivateKeyPassphrase().getBytes(StandardCharsets.UTF_8);
}
jsch.addIdentity("ID", sftpConfig.getPrivateKey(), null, passphrase);
}
@@ -232,11 +228,7 @@ public class SftpOperations implements RemoteFileOperations<SftpRemoteFile> {
LOG.debug("Using private key uri : {}", sftpConfig.getPrivateKeyUri());
byte[] passphrase = null;
if (isNotEmpty(sftpConfig.getPrivateKeyPassphrase())) {
- try {
- passphrase = sftpConfig.getPrivateKeyPassphrase().getBytes("UTF-8");
- } catch (UnsupportedEncodingException e) {
- throw new JSchException("Cannot transform passphrase to byte[]", e);
- }
+ passphrase = sftpConfig.getPrivateKeyPassphrase().getBytes(StandardCharsets.UTF_8);
}
try {
InputStream is = ResourceHelper.resolveMandatoryResourceAsInputStream(endpoint.getCamelContext(), sftpConfig.getPrivateKeyUri());
@@ -248,6 +240,7 @@ public class SftpOperations implements RemoteFileOperations<SftpRemoteFile> {
}
}
+
if (sftpConfig.getKeyPair() != null) {
LOG.debug("Using private key information from key pair");
KeyPair keyPair = sftpConfig.getKeyPair();
@@ -689,7 +682,7 @@ public class SftpOperations implements RemoteFileOperations<SftpRemoteFile> {
final List<SftpRemoteFile> list = new ArrayList<>();
@SuppressWarnings("rawtypes")
- Vector files = channel.ls(path);
+ List files = channel.ls(path);
// can return either null or an empty list depending on FTP servers
if (files != null) {
for (Object file : files) {
@@ -1020,7 +1013,7 @@ public class SftpOperations implements RemoteFileOperations<SftpRemoteFile> {
try {
@SuppressWarnings("rawtypes")
- Vector files = channel.ls(directory);
+ List files = channel.ls(directory);
// can return either null or an empty list depending on FTP servers
if (files == null) {
return false;
@@ -1050,7 +1043,7 @@ public class SftpOperations implements RemoteFileOperations<SftpRemoteFile> {
LOG.trace("fastExistsFile({})", name);
try {
@SuppressWarnings("rawtypes")
- Vector files = channel.ls(name);
+ List files = channel.ls(name);
if (files == null) {
return false;
}
@@ -1099,7 +1092,7 @@ public class SftpOperations implements RemoteFileOperations<SftpRemoteFile> {
} catch (Exception e) {
String message = e.toString();
if (e instanceof Throwable) {
- throw new RuntimeCamelException(message, (Throwable)e);
+ throw new RuntimeCamelException(message, e);
}
throw new RuntimeCamelException(message);
}