Hi Guilleaume Nodet
I found the issue
Issue lies with the way we are reading IoBuffer
Wrong way of reading::
==================
IoBuffer msg = (IoBuffer)future.getMessage();
msg.flip();
Buffer buf = new Buffer(msg.array());
Correct way of reading::
=================
IoBuffer msg = (IoBuffer)future.getMessage();
msg.flip();
int r=ioBuffer.remaining();
byte[] b=new byte[r];
ioBuffer.get(b,0,r);
Buffer buf = new Buffer(b);
Thanks
Vikram
________________________________________
From: Vikram Darsi [[email protected]]
Sent: 03 November 2015 12:23:37
To: [email protected]; [email protected]
Subject: RE: Apache SSHD and Apache MINA integration
Hi Guillaume Nodet
Thanks for the reply
I tried both the approaches and below are the issues
Approach 1: Based on the code I have written
I ensured to connect to a dummy server, but below is the exception thrown
2015-11-03 12:00:26,943 | WARN | oupCloseable-6-1 |
shHandler$DefaultIoConnectFuture | 210 - org.apache.sshd.core - 0.14.0 |
Listener threw an exception
java.lang.IllegalStateException: No session available
at
org.apache.sshd.common.session.AbstractSession.getSession(AbstractSession.java:215)[210:org.apache.sshd.core:0.14.0]
at
org.apache.sshd.common.session.AbstractSession.getSession(AbstractSession.java:198)[210:org.apache.sshd.core:0.14.0]
at
org.apache.sshd.SshClient$4.operationComplete(SshClient.java:305)[210:org.apache.sshd.core:0.14.0]
at
org.apache.sshd.SshClient$4.operationComplete(SshClient.java:298)[210:org.apache.sshd.core:0.14.0]
at
org.apache.sshd.common.future.DefaultSshFuture.notifyListener(DefaultSshFuture.java:269)[210:org.apache.sshd.core:0.14.0]
at
org.apache.sshd.common.future.DefaultSshFuture.addListener(DefaultSshFuture.java:214)[210:org.apache.sshd.core:0.14.0]
at
org.apache.sshd.SshClient.connect(SshClient.java:298)[210:org.apache.sshd.core:0.14.0]
Approach 2:
This is working fine while writing to the mina core Iosession, but,
reading from the ioSession is a problem in my case
useReadOperation is set to true inorder to read
acceptor.getSessionConfig().setUseReadOperation(true);
Code written to read is as below
class MyAsyncSshHandlerReader implements IoFutureListener<ReadFuture>,
AutoCloseable {
private final org.apache.sshd.common.io.IoSession ioSession;
public MyAsyncSshHandlerReader(org.apache.sshd.common.io.IoSession
ioSession) {
this.ioSession = ioSession;
minaCoreIoSession.read().addListener(this);
}
@Override
public void close() throws Exception {
// TODO Auto-generated method stub
}
@Override
public void operationComplete(ReadFuture future) {
if(future.isRead() && !future.isClosed()){
msg.flip();
Buffer buf = new Buffer(msg.array());
try {
if(AbstractSession.getSession(ioSession) != null){
AbstractSession.getSession(ioSession).messageReceived(buf);
}
} catch (Exception e) {
e.printStackTrace();
}
minaCoreIoSession.read().addListener(this);
}
}
}
While decoding the message, I am getting
SshException: Getting Invalid packet length :0 is received, How can I debug
the issue further?
Is the code written to read has any issues?
The same issue is posted in stack overflow (packet capture is attached there)
http://stackoverflow.com/questions/33473193/apache-mina-and-sshd-reverse-ssh-invalid-packet-length-0
Thanks
Vikram
________________________________________
From: Guillaume Nodet [[email protected]]
Sent: 03 November 2015 02:20:46
To: [email protected]
Subject: Re: Apache SSHD and Apache MINA integration
It may be easier for you to go to a lower level though.
SshClient client = SshClient.setUpDefaultClient();
ClientSession session = new ClientSessionImpl(client, new MinaSession(null,
ioSession));
session.setUsername(...);
...
I suppose your code snippet should work too, though you'd have to call
client.connect() with a dummy address.
2015-10-21 8:24 GMT+02:00 Vikram Darsi <[email protected]>:
> Hi
>
> We have a Netconf protocol implementation on top of Apache MINA and Apache
> SSHD, and currently working on new feature "reverse SSH"
>
>
> 1. Apache MINA's NioSocketAcceptor is used to accept incoming connections
> and a StreamIOhandler is set to it.
>
> 2. So, when a connection is accepted, we have a IoSession, InputStream and
> OutputStream with us
>
> 3. As per the concept of reverseSSH, all further request's should use the
> same channel.
>
> Here comes the need to attach the IoSession to Apache SSHD's SshClient
>
> The following is the code snippet written for achieving this
>
>
> sshClient.setIoServiceFactoryFactory(new IoServiceFactoryFactory() {
> @Override
> public IoServiceFactory create(final FactoryManager manager) {
> return new MinaServiceFactory(manager) {
> @Override
> public IoConnector createConnector(final IoHandler
> handler) {
> try {
> return new Nio2Connector(manager, handler,
> AsynchronousChannelGroup.withThreadPool(MoreExecutors.sameThreadExecutor()))
> {
> @Override
> public IoConnectFuture connect(final
> SocketAddress address) {
> DefaultIoConnectFuture
> defaultIoConnectFuture = new DefaultIoConnectFuture(null);
>
> defaultIoConnectFuture.setSession(ioSession);
> return defaultIoConnectFuture;
> }
> };
> } catch (IOException e) {
> // FIXME
> e.printStackTrace();
> }
> return null;
> }
> };
> }
> });
>
>
> sshClient.start();
>
> Are these steps correct? If not, can you please let us know the correct
> steps.
>
> 4. For further communication can we use this SshClient API to talk to the
> devices in usual manner?
>
>
>
> Thanks
> Vikram
>
>
> This email and attachments may contain privileged or confidential
> information intended only for the addressee(s) indicated. The sender does
> not waive any of its rights, privileges or protections respecting this
> information. If you are not the named addressee, an employee, or agent
> responsible for sending this message to the named addressee (or this
> message was received by mistake), you are not authorized to read, print,
> retain, copy or disseminate this message or any part of it. If received in
> error, please notify us immediately by e-mail, discard any paper copies and
> delete all electronic files of the email.
>
> Computer viruses can be transmitted via email. The recipient should check
> this email and any attachments for viruses. Email transmission cannot be
> guaranteed to be secured or error-free as information could be intercepted,
> corrupted, lost, destroyed, arrive late or incomplete, or contain viruses.
> The sender accepts no liability for any damage caused by any transmitted
> viruses or errors or omissions in the contents of this message.
>
> Overture Networks, Inc. 637 Davis Drive, Morrisville, NC USA 27560
> www.overturenetworks.com
>
This email and attachments may contain privileged or confidential information
intended only for the addressee(s) indicated. The sender does not waive any of
its rights, privileges or protections respecting this information. If you are
not the named addressee, an employee, or agent responsible for sending this
message to the named addressee (or this message was received by mistake), you
are not authorized to read, print, retain, copy or disseminate this message or
any part of it. If received in error, please notify us immediately by e-mail,
discard any paper copies and delete all electronic files of the email.
Computer viruses can be transmitted via email. The recipient should check this
email and any attachments for viruses. Email transmission cannot be guaranteed
to be secured or error-free as information could be intercepted, corrupted,
lost, destroyed, arrive late or incomplete, or contain viruses. The sender
accepts no liability for any damage caused by any transmitted viruses or errors
or omissions in the contents of this message.
Overture Networks, Inc. 637 Davis Drive, Morrisville, NC USA 27560
www.overturenetworks.com
This email and attachments may contain privileged or confidential information
intended only for the addressee(s) indicated. The sender does not waive any of
its rights, privileges or protections respecting this information. If you are
not the named addressee, an employee, or agent responsible for sending this
message to the named addressee (or this message was received by mistake), you
are not authorized to read, print, retain, copy or disseminate this message or
any part of it. If received in error, please notify us immediately by e-mail,
discard any paper copies and delete all electronic files of the email.
Computer viruses can be transmitted via email. The recipient should check this
email and any attachments for viruses. Email transmission cannot be guaranteed
to be secured or error-free as information could be intercepted, corrupted,
lost, destroyed, arrive late or incomplete, or contain viruses. The sender
accepts no liability for any damage caused by any transmitted viruses or errors
or omissions in the contents of this message.
Overture Networks, Inc. 637 Davis Drive, Morrisville, NC USA 27560
www.overturenetworks.com