473,657 Members | 2,595 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 6142
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.3 1.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.Collecti ons;
using System.Net;
using System.Net.Secu rity;
using System.Net.Sock ets;
using System.Security .Authentication ;
using System.Text;
using System.Security .Cryptography.X 509Certificates ;
using System.IO;

namespace Examples.System .Net
{
public class SslTcpClient
{

public static void RunClient()
{
TcpClient client = new TcpClient("10.3 1.46.20", 5022);
Console.WriteLi ne("Client connected");

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

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

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

}
static string ReadMessage(Ssl Stream 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.G etDecoder();
char[] chars = new char[decoder.GetChar Count(buffer, 0,
bytes)];
decoder.GetChar s(buffer, 0, bytes, chars, 0);
messageData.App end(chars);
// Check for EOF.
if (messageData.To String().IndexO f("<EOF>") != -1)
{
break;
}
} while (bytes != 0);

return messageData.ToS tring();

}

public static int Main(string[] args)
{
SslTcpClient.Ru nClient();
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...@discus sions.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...@discus sions.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...@discus sions.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...@discus sions.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
2722
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 'x509_extensions' and/or 'req_extensions' fails to generate/sign a certificate with the desired X.509 extensions included in the signed certificate. The extensions in my "openssl.cnf" file work just fine with manual OpenSSL commands. Also, I am...
3
6056
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 Php4 and php4-extensions packages. So, i installed :
0
2764
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 certificate. When I tried executing the code I get the following error: -------------------
2
5273
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: ../configure --with-openssl --enable-odbc --with-perl --enable-multibyte
17
10006
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
15233
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 OpenSSL's <evp.h> That file is located in /usr/include/openssl/evp.h but when I put the directory in the configure option
4
6584
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 tried to understand the error messages but for me they aren't useful. And now I'm here and hope that somebody has experience and can tell me the error. This is the Code for the server: #define _CRT_SECURE_NO_DEPRECATE
5
7948
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, it can open the file. However, when I run Php5 I (now) get this error message: "Unable to find the wrapper "https" - did you forget to enable it when you configured PHP?" This is new. Last time I messed with this, I merely got:
4
4878
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 the latest version of pre-compiled version of OpenSSL from /www.shininglightpro.com/products/ Win32OpenSSL.html website. So AFAIK there is no need for Perl script compilation and NASM, MASM issue as long as I have the pre-compiled binaries. If I'm...
0
8392
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8823
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8730
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8605
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5632
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4151
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4301
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
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 we have to send another system
2
1607
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.