Openssl and Telnet

S

Sharief

Dear All,

I must write a client program in C# which will communicate with a switch
throught telnet.
When I create a socket connection on port 22, the switch responds with some
text and at the end with some unreadable characters. I found out that the
operating system of the switch is redhat and the protocol =
SSH-2.0-openssh_3.9p1.

My problem:
1. I connect with socket <ip-address>:<port 22>
2. I don't get the prompt:"login: " but my programs says connected
3. after a while a timeout occurs with the comment: "Timed Out waiting for :
login"


My question is:
- Where can I download a ssl classfile for c# which support openssl
- How can I catch a certificate if a server sends one and how can I write my
one
- do you have an example how to write this (I' am new to C# + ssl)

Kind regards and hope someone can point me in the right direction
 
A

Arne Vajhøj

Sharief said:
I must write a client program in C# which will communicate with a switch
throught telnet.
When I create a socket connection on port 22, the switch responds with some
text and at the end with some unreadable characters. I found out that the
operating system of the switch is redhat and the protocol =
SSH-2.0-openssh_3.9p1.

My problem:
1. I connect with socket <ip-address>:<port 22>
2. I don't get the prompt:"login: " but my programs says connected
3. after a while a timeout occurs with the comment: "Timed Out waiting for :
login"


My question is:
- Where can I download a ssl classfile for c# which support openssl
- How can I catch a certificate if a server sends one and how can I write my
one
- do you have an example how to write this (I' am new to C# + ssl)

Try one of:

http://www.tamirgal.com/home/dev.aspx?Item=SharpSsh
http://www.routrek.co.jp/en/product/varaterm/granados.html

Arne
 
S

Sharief

Hi Arne Thx for your reply but this didnot solve my problem:

What I actually try to do is:
1). Try to setup a connection ==> TcpClient client = new
TcpClient("10.31.46.20", 5022); (5022 is the port. This is the ssh port
nummer on the system)

2). Now I must send or receive some authentication (in may case
authentication is not needed) but what If I do need authentication? At this
point I don't now how to accomplish this

3). When authentication was successful, then the system (where i try to
connect to) will send me a login prompt,

4). Then my program will send the loginname and will wait for the password
prompt.

3). My program will send the password and will wait for the terminal
settings etc

So what I want my program to do after a succesful connect is, wait for some
specific character like (login: ) and send some string to the system.

I have put my test program here but I am stuck right now. I don't know how
to send or wait for athentication and also don't know how to send commands to
the system

I hope you or someone can help me wth this.

The code below I found at:
http://msdn2.microsoft.com/en-us/library/system.net.security.sslstream.aspx


==========================================
using System;
using System.Collections;
using System.Net;
using System.Net.Security;
using System.Net.Sockets;
using System.Security.Authentication;
using System.Text;
using System.Security.Cryptography.X509Certificates;
using System.IO;

namespace Examples.System.Net
{
public class SslTcpClient
{

public static void RunClient()
{
TcpClient client = new TcpClient("10.31.46.20", 5022);
Console.WriteLine("Client connected");

SslStream sslStream = new SslStream(client.GetStream());
<< AT THIS POINT AUTHENTICATION MUST TAKE PLACE >>>
string serverMessage = ReadMessage(sslStream);

byte[] message = Encoding.UTF8.GetBytes("Hello from
client.<EOF>");
sslStream.Write(message);
sslStream.Flush();

//read message from server
//string serverMessage = ReadMessage(sslStream);
Console.WriteLine("server says: {0}", serverMessage);
//close connection
client.Close();

}
static string ReadMessage(SslStream sslStream)
{
// Read the message sent by the server.
// The end of the message is signaled using the
// "<EOF>" marker.
byte[] buffer = new byte[2048];
StringBuilder messageData = new StringBuilder();
int bytes = -1;
do
{
bytes = sslStream.Read(buffer, 0, buffer.Length);

// Use Decoder class to convert from bytes to UTF8
// in case a character spans two buffers.
Decoder decoder = Encoding.UTF8.GetDecoder();
char[] chars = new char[decoder.GetCharCount(buffer, 0,
bytes)];
decoder.GetChars(buffer, 0, bytes, chars, 0);
messageData.Append(chars);
// Check for EOF.
if (messageData.ToString().IndexOf("<EOF>") != -1)
{
break;
}
} while (bytes != 0);

return messageData.ToString();

}

public static int Main(string[] args)
{
SslTcpClient.RunClient();
return 0;
}
}
}
 
J

Jon Skeet [C# MVP]

So what I want my program to do after a succesful connect is, wait for some
specific character like (login: ) and send some string to the system.

You seem to be under the impression that SSH is just "telnet over a
secure connection". My understanding is that SSH doesn't work like
that - the authentication is part of the initial protocol, not just
some text which happens to go back and forth as with telnet.

I think it's worth reading up on SSH itself before going any further
in code.

Jon
 
S

Sharief

Okay Jon thx I accually don't know ssh. I was busy reading a ssh book. In my
case I think I have to setup a secure shell in this shell I must send
commands via my program and receive the screen ouput in a string. But how do
i do this? i am looking something which can point me in the right direction
to do this.

Sharief
 
J

Jon Skeet [C# MVP]

Okay Jon thx I accually don't know ssh. I was busy reading a ssh book. In my
case I think I have to setup a secure shell in this shell I must send
commands via my program and receive the screen ouput in a string. But how do
i do this? i am looking something which can point me in the right direction
to do this.

I think reading the SSH book and then using one of the libraries Arne
pointed you at is probably the way to go. Until you understand what's
happening underneath, you could waste a lot of time.

Jon
 
S

Sharief

Thxs will do so

Jon Skeet said:
I think reading the SSH book and then using one of the libraries Arne
pointed you at is probably the way to go. Until you understand what's
happening underneath, you could waste a lot of time.

Jon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top