Comments (4)
In fact I'm working on a project for an IAAS offer of cloud computing. And It's all about the provisionning of the netscreen ISG 1000 series firewall of JUNIPER.
from sshj.
Can you describe how to reproduce this?
from sshj.
First of all thank you for replying to my issue. It's really a tough one.
In fact It's simple, you just develop a junit test for example to a host, in able to open , and close, several connexion via a loop.
Here is an the whole code of my testing junit:
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Date;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import net.schmizz.sshj.SSHClient;
import net.schmizz.sshj.connection.channel.direct.Session;
import net.schmizz.sshj.connection.channel.direct.Session.Shell;
import org.apache.log4j.Logger;
import org.junit.Ignore;
import com.orange.fcr.exception.TimeOutException;
@Ignore
public class TestSSH2 {
private static Logger logger = Logger.getLogger(TestSSH2.class);
String TIMEOUT_ERROR_MESSAGE = "TimeOut: unable to have a response from the device";
private long send(OutputStream out, String commande) throws IOException {
long count = 0L;
count = commande.getBytes().length;
out.write(commande.getBytes(), 0, commande.getBytes().length);
out.flush();
return count;
}
public SSHClient sshClient;
@SuppressWarnings("static-access")
public String receive(InputStream in, int bufSize, int sshTimeOut) throws IOException,
InterruptedException, TimeOutException {
long deadline = 0;
if (sshTimeOut >= 0){
deadline = new Date().getTime() + sshTimeOut;
}
int read = 0;
StringBuilder resultat = new StringBuilder();
Pattern p = Pattern.compile("^*([a-zA-Z0-9()]+)->\\s*$");
Matcher m;
int count = 0;//nomber of bytes to read
//waiting for the first bytes to read
while ((count=in.available()) < 0) {
if ((deadline != 0) && new Date().getTime() > deadline) {
throw new TimeOutException(TIMEOUT_ERROR_MESSAGE);
}
try {
Thread.currentThread().sleep(100);
}catch (InterruptedException ignored) {
/* ignore */
}
}
//begin reading the bytes
while(((count =in.available()) >= 0)){
byte[] buf = new byte[bufSize];
if(count > 0){
read = in.read(buf);
}
else{
read = 0;
}
if (read > 0) {
String res = new String(buf, 0, read);
resultat.append(res);
}
m = p.matcher(resultat);
//Go out when I find a first read
if (m.find()) {
break;
}//deadline passed: timeout exception finishing to read the message
else if ((deadline != 0) && (new Date().getTime() > deadline)) {
throw new TimeOutException(TIMEOUT_ERROR_MESSAGE);
}
}
return resultat.toString();
}
public void connect() throws IOException{
this.sshClient = new SSHClient();
sshClient.addHostKeyVerifier("c5:c6:59:24:b6:9c:62:31:29:6a:c1:c4:a5:fa:ea:05");
sshClient.connect("10.1.31.43", 22);
sshClient.authPassword("dihadmin", "dihadmin");
}
public static void main(String... args) throws Exception {
TestSSH2 testSSH2 = new TestSSH2();
for(int i = 0; i < 300; i++){
testSSH2.connect();
try {
Session session = testSSH2.sshClient.startSession();
Shell shell1 = null;
try {
logger.error("begin loop n°:"+i);
session.allocateDefaultPTY();
shell1 = session.startShell();
String resultat1;
String resultat2;
String resultat3;
logger.error("loop n°:"+i + " preambule receive:");
testSSH2.receive(shell1.getInputStream(),
shell1.getLocalMaxPacketSize(),2000);
logger.error("loop n°:"+i + " send n°1");
testSSH2.send(shell1.getOutputStream(), "get console\n");
logger.error("loop n°:"+i + "receive n°1");
resultat1 = testSSH2.receive(shell1.getInputStream(),
shell1.getLocalMaxPacketSize(),2000);
logger.error("loop n°:"+i + " send n°2");
testSSH2.send(shell1.getOutputStream(), "get vrouter\n");
logger.error("loop n°:"+i + " receive n°2");
resultat2 = testSSH2.receive(shell1.getInputStream(),
shell1.getLocalMaxPacketSize(),2000);
logger.error("loop n°:"+i + " send n°3");
testSSH2.send(shell1.getOutputStream(), "get config\n");
logger.error("loop n°:"+i + " receive n°3");
resultat3 = testSSH2.receive(shell1.getInputStream(),
shell1.getLocalMaxPacketSize(),3000);
logger.error("loop n°:"+i + " send n°4");
testSSH2.send(shell1.getOutputStream(), "exit\n");
logger.error("response for cmd1:"+resultat1);
logger.error("response for cmd2:"+resultat2);
logger.error("response for cmd3:"+resultat3);
} finally {
shell1.close();
session.close();
}
} finally {
testSSH2.sshClient.disconnect();
}
}
}
}
As you can see in this code, I'm in a loop for, I'm creating for each iteration, a new sshClient base on the API of sshj.
I disconnect from it at the end.
I have no errors for about 100 connexions, and then it stops. I'm not able to connect to the device.
Anyway, it is quite random the issue, It happens specially when you try to make connexions one after the other.
Any help can be welcomed. Don't hesitate if you nedd more information!!!
from sshj.
What SSH server is this? I can't reproduce on my end, using OpenSSH sshd 5.6. Complete debug-level logs would be very helpful.
from sshj.
Related Issues (20)
- Broken pipe errors after upgrading to 0.36.0 HOT 6
- SFTPs attempt to check whether a target file is a directory throws Permission Denied Exception when the target file does not exist
- net.schmizz.sshj.common.SSHRuntimeException: no such algorithm: X25519 for provider BC HOT 10
- NullpointerException on downloadFile (starts with version 0.34) HOT 4
- NullPointerException on `OpenSSHKeyV1KeyFile.java` HOT 2
- Regression writing known host entry key string
- SSHJ usage on Android app in Kotlin HOT 2
- No initialization of public key depending on constructor usage of file key provider
- False-alarm timeout exception when waiting for key exchange to complete HOT 1
- Bad packet received by server when hearbeat is enabled HOT 1
- SFTP RSA negotiation vulnerability HOT 3
- [Feature request] compatibility with OTP
- Terrapin Vulnerability CVE-2023-48795 HOT 1
- Does CVE-2023-48795 affect sshj ? HOT 4
- Suggestions on Improving the Security Algorithm for Calculating Fingerprints HOT 1
- Support for connected sockets HOT 1
- I have tried to disconnect the sshclient in my java code, but the operating system did not disconnect port 22? HOT 2
- SCP upload to Windows 11 Open SSH fails with no such file or directory error HOT 3
- RemoteFile.RemoteFileInputStream does not hanbdle read with len=0 correctly
- Invalid algorithm identifier
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sshj.