From c215b141f9cf935ef26650993cf3455f5d0e7a31 Mon Sep 17 00:00:00 2001 From: "anh.phamtu" Date: Tue, 13 Aug 2024 12:20:30 +0700 Subject: [PATCH] update jsch to com.github.mwiede:jsch:0.2.19 --- .github/workflows/ci.yml | 24 ++++++++++--------- sftp-connector/config/variables.yaml | 9 ++++--- sftp-connector/pom.xml | 4 ++-- .../sftp/service/SftpClientService.java | 7 ++++++ 4 files changed, 26 insertions(+), 18 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b0d9402..444bfef 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -32,11 +32,12 @@ jobs: - name: Install and start SFTP run: | + sudo apt install sshpass sudo apt install openssh-server sudo systemctl enable ssh sudo systemctl start ssh sudo sh -c 'echo "PubkeyAcceptedAlgorithms +ssh-rsa" >> /etc/ssh/sshd_config' - sudo systemctl restart ssh + sudo systemctl try-reload-or-restart ssh sudo cat /etc/ssh/sshd_config - name: Create a test user account @@ -46,16 +47,16 @@ jobs: echo "adding user to group ${sshGroup}" sudo useradd -s /bin/bash -d /home/usr -m -g ${sshGroup} -p $(echo pwd | openssl passwd -1 -stdin) usr - sudo -u usr ssh-keygen -t rsa -N "123456" -f /home/usr/.ssh/sftptest - sudo -u usr sh -c 'cat /home/usr/.ssh/sftptest.pub >> /home/usr/.ssh/authorized_keys' - sudo chmod -R 600 /home/usr/.ssh/ - sudo chmod 700 /home/usr/.ssh/authorized_keys - sudo cat /home/usr/.ssh/sftptest.pub - sudo cat /home/usr/.ssh/authorized_keys - - sudo cp /home/usr/.ssh/sftptest ${GITHUB_WORKSPACE}/sftp-connector-test/src_test/com/axonivy/connector/sftp/test/sftptest - sudo ssh-keygen -p -P "123456" -N "123456" -m pem -f ${GITHUB_WORKSPACE}/sftp-connector-test/src_test/com/axonivy/connector/sftp/test/sftptest - sudo chown "$(whoami)" ${GITHUB_WORKSPACE}/sftp-connector-test/src_test/com/axonivy/connector/sftp/test/sftptest + ssh-keygen -t rsa -b 4096 -N "" -f ~/.ssh/sftptest + sudo -u usr mkdir /home/usr/.ssh/ + sudo cat ~/.ssh/sftptest.pub >> /home/usr/.ssh/authorized_keys + sudo chown -R usr /home/usr/.ssh + sudo chmod -R 600 /home/usr/.ssh + sudo chmod 600 /home/usr/.ssh/authorized_keys + echo "${sudo cat /home/usr/.ssh/authorized_keys}" + sudo ls -la /home/usr/.ssh + cp ~/.ssh/sftptest ${GITHUB_WORKSPACE}/sftp-connector-test/src_test/com/axonivy/connector/sftp/test/sftptest + # ssh -v -o StrictHostKeyChecking=no -i ~/.ssh/sftptest usr@localhost 'cd ~/.ssh/' - name: Setup Maven uses: stCarolas/setup-maven@v5 @@ -68,6 +69,7 @@ jobs: - name: Print out log run: | sudo journalctl -u ssh + echo "=======================================================" sudo cat /var/log/auth.log # - name: Publish Unit Test Results diff --git a/sftp-connector/config/variables.yaml b/sftp-connector/config/variables.yaml index 272aa86..afe98cb 100644 --- a/sftp-connector/config/variables.yaml +++ b/sftp-connector/config/variables.yaml @@ -11,15 +11,14 @@ Variables: username: 'usr' # Auth type to the SFPT server: password OR ssh - auth: 'password' + auth: 'ssh' # The password to the SFTP server # [password] - password: pwd + password: '' # The ssh key string to SFTP server # [secret private key] - secret_sshkey: '' - + secret.sshkey: '' # The ssh key passphrase - secret_sshpassphrase: '' + secret.sshpassphrase: '' diff --git a/sftp-connector/pom.xml b/sftp-connector/pom.xml index 119c50d..6d43de1 100644 --- a/sftp-connector/pom.xml +++ b/sftp-connector/pom.xml @@ -11,9 +11,9 @@ - com.jcraft + com.github.mwiede jsch - 0.1.55 + 0.2.19 diff --git a/sftp-connector/src/com/axonivy/connector/sftp/service/SftpClientService.java b/sftp-connector/src/com/axonivy/connector/sftp/service/SftpClientService.java index a2d2616..633248c 100644 --- a/sftp-connector/src/com/axonivy/connector/sftp/service/SftpClientService.java +++ b/sftp-connector/src/com/axonivy/connector/sftp/service/SftpClientService.java @@ -8,6 +8,7 @@ import java.util.ArrayList; import java.util.Date; import java.util.List; +import java.util.Properties; import org.apache.commons.lang3.StringUtils; import org.apache.log4j.Logger; @@ -56,6 +57,7 @@ public class SftpClientService implements AutoCloseable { */ public SftpClientService(String host, int port, String username, String authType, String password, String keyString, String passphrase) throws IOException { System.out.println(keyString); + System.out.println(passphrase); try { JSch jsch = new JSch(); @@ -63,6 +65,11 @@ public SftpClientService(String host, int port, String username, String authType if (StringUtils.isEmpty(authType) || PASSWORD.equalsIgnoreCase(authType)) { session.setPassword(password); } else { + session.setConfig("PreferredAuthentications", "publickey"); +// Properties config = new Properties(); +// config.put("PubkeyAcceptedKeyTypes", "ssh-rsa"); +// config.put("HostKeyAlgorithms", "ssh-rsa"); +// session.setConfig(config); jsch.addIdentity(null, keyString.getBytes(), null, passphrase.getBytes()); }