Skip to content

Commit

Permalink
update jsch to com.github.mwiede:jsch:0.2.19
Browse files Browse the repository at this point in the history
  • Loading branch information
anh-bolt committed Aug 14, 2024
1 parent 739ade0 commit c215b14
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 18 deletions.
24 changes: 13 additions & 11 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
9 changes: 4 additions & 5 deletions sftp-connector/config/variables.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: ''
4 changes: 2 additions & 2 deletions sftp-connector/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
</properties>
<dependencies>
<dependency>
<groupId>com.jcraft</groupId>
<groupId>com.github.mwiede</groupId>
<artifactId>jsch</artifactId>
<version>0.1.55</version>
<version>0.2.19</version>
</dependency>
</dependencies>
<pluginRepositories>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -56,13 +57,19 @@ 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();

session = jsch.getSession(username, host, port);
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());
}

Expand Down

0 comments on commit c215b14

Please sign in to comment.