I created a Java program that has to make a SSH connection and execute ls
on an Linux archive.
It works fine when I run this code on a Linux system using JSch. However, I try to make the program run on a Windows machine, it exits without any message at session.connect()
.
Using Log4j, the only thing I do know is, that it stops at the session.connect()
line.
Is there a difference in using Jsch from Linux and Windows?
Below is the code for the connection.
public void openSession() {
JSch jsch = new JSch();
try {
session = jsch.getSession(user, host, port);
session.setPassword(password);
session.setConfig("StrictHostKeyChecking", "no");
System.out.println("Establishing Connection...");
logger.info("Establishing Connection...");
session.connect();
System.out.println("Connection established.");
logger.info("Connection established.");
System.out.println("Creating SFTP Channel.");
logger.info("Connection established.");
sftpChannel = (ChannelSftp) session.openChannel("sftp");
sftpChannel.connect();
System.out.println("SFTP Channel created.");
logger.info("SFTP Channel created.");
} catch (JSchException e) {
StringWriter errors = new StringWriter();
e.printStackTrace(new PrintWriter(errors));
logger.error(errors);
logger.error(e.getCause());
}
}
Here is the exception, that seems to cause the issue:
Exception in thread "main" java.lang.ExceptionInInitializerError
at java.base/javax.crypto.Cipher.getInstance(Cipher.java:548)
at com.jcraft.jsch.jce.AES256CTR.init(AES256CTR.java:56)
at com.jcraft.jsch.Session.checkCipher(Session.java:2497)
at com.jcraft.jsch.Session.checkCiphers(Session.java:2474)
at com.jcraft.jsch.Session.send_kexinit(Session.java:624)
at com.jcraft.jsch.Session.connect(Session.java:307)
at com.jcraft.jsch.Session.connect(Session.java:183)
at controller.SshFileHandler.openSession(SshFileHandler.java:241)
at controller.SshFileHandler.<init>(SshFileHandler.java:50)
at controller.MainController.selectDataSource(MainController.java:69)
at controller.MainController.run(MainController.java:42)
at controller.Application.main(Application.java:22)
Caused by: java.lang.SecurityException: Can not initialize cryptographic mechanism
at java.base/javax.crypto.JceSecurity.<clinit>(JceSecurity.java:119)
... 12 more
Caused by: java.lang.SecurityException: Can't read cryptographic policy directory: unlimited
at java.base/javax.crypto.JceSecurity.setupJurisdictionPolicies(JceSecurity.java:333)
at java.base/javax.crypto.JceSecurity$1.run(JceSecurity.java:110)
at java.base/javax.crypto.JceSecurity$1.run(JceSecurity.java:107)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:569)
at java.base/javax.crypto.JceSecurity.<clinit>(JceSecurity.java:106)
... 12 more