473,503 Members | 1,818 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Openssl and Telnet

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
Dec 17 '07 #1
6 6128
Sharief wrote:
>
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/.../granados.html

Arne
Dec 18 '07 #2
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/lib...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;
}
}
}

"Arne Vajhøj" wrote:
Sharief wrote:

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/.../granados.html

Arne
Dec 18 '07 #3
On Dec 18, 1:50 pm, Sharief <Shar...@discussions.microsoft.comwrote:

<snip>
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
Dec 18 '07 #4
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

"Jon Skeet [C# MVP]" wrote:
On Dec 18, 1:50 pm, Sharief <Shar...@discussions.microsoft.comwrote:

<snip>
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
Dec 18 '07 #5
On Dec 18, 2:47 pm, Sharief <Shar...@discussions.microsoft.comwrote:
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
Dec 18 '07 #6
Thxs will do so

"Jon Skeet [C# MVP]" wrote:
On Dec 18, 2:47 pm, Sharief <Shar...@discussions.microsoft.comwrote:
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
Dec 18 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2714
by: User1001 | last post by:
I have been trying to enable/use specific OpenSSL extensions that I use in generating certificates manually, via PHP5 + php5-openssl module/extension. Filling out the "configargs" array with...
3
6042
by: nanard | last post by:
Hi,Bonjour, I m running FreeBSD 4.10 STABLE and using Apache 1.3.x and PHP4. Today, i updated php4 from Ports Tree and there was lot of change. Indeed, no more php4-something package... only...
0
2759
by: John Bergstrom | last post by:
Hello everyone! I wrote a simple perl program to encrypt a string using Crypt::OpenSSL::RSA. Everything as described in the module documentation. The public key is a valid X.509 encrypted...
2
5263
by: Christopher Murtagh | last post by:
Greetings, I'm trying to build 7.3.4 and I've come across two problems, one during the configure and the other afterward. Problem 1) Trying to build with openssl support gives this: ...
17
9948
by: cpptutor2000 | last post by:
Could some C guru please help me? I have a simple piece of code as: #include <stdio.h> #include <stdlib.h> #include <openssl/rand.h> int main(){ unsigned char temp; RAND_bytes(temp, 4);
1
15225
by: laredotornado | last post by:
Hello, I downloaded PHP 4.4.4 and am trying to install for Apache 2 on Fedora Core 5. However when trying to configure with openssl, I get this error, configure: error: Cannot find...
4
6564
by: Patrick | last post by:
Hello, I'm currently trying the OpenSSL Library, but I got some problems. I want to create a server and client application that communicate through the OpenSSL API, but this code doesn't work. I...
5
7923
by: Chuck Anderson | last post by:
I run Apache 2.0.55, and Php (both 4.4.1 and 5.2.5) on my home PC (Windows XP). One of the scripts that I run daily needs to access a secure URL (https://..............). When I am running Php4,...
4
4870
by: Tan | last post by:
Hi folk, I'm trying to install latest OpenSSL version in VS2008 Express Edition on WinXP. I have downloaded and installed the redistributable for VC+ +2008 (including SP1), and also installed...
0
7202
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7280
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7330
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6991
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7460
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5014
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4672
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1512
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
380
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.