How to use an existing Putty-SSH-Connection with HttpClient - c#

I have set up a SSH connection to a remote computer on a specific local port via Putty.
It works fine, as I can use it with Firefox, setting the SOCKS-Host on this port.
I want to use this connection with my program, where I use HttpClient to do the work (send data to DB).
Is there a way to access the port with HttpClient? Simply putting it into the address didn't work.
Tried to attend WebProxy("127.0.0.1", port) to the client, but it didn't work either.
Any suggestions?

You have set up a SOCKS proxy, not an HTTP proxy. I don't usually code C#, so I did a google search, but it is unclear to me whether WebProxy directly supports SOCKS proxies - to me it seems SOCKS support is lacking in .NET, unless you can find some freely available, third party classes.
You can look into using a SOCKS proxy with WebProxy - you can probably achieve the same thing using some wrapper class. Another option is set up Polipo or Privoxy, and then use your existing code changing only the port for your WebProxy call. They are both HTTP proxies that feature proxy chaining with existing SOCKS proxies - configure to use your SSH SOCKS proxy, and you're good to go...

Related

How to handle HTTP Connect in .NET?

I would like to handle HTTP on very low level - at the moment I'm stuck with HTTP CONNECT verb. It looks like HttpListener doesn't have access to these request because they are handled somewhere inside HTTP API or HTTP.SYS. I'm able to handle such requests with native TcpListener but in such case I would lose all HTTP functionality = I would implement HTTP from scratch.
I also checked FiddlerCore but it also handles these requests on some Win API layer. Is there any pure .NET HTTP stack?
Edit: I'm working on HTTP proxy with some additional request analysis and statistics so I don't want to lose HTTP parsing and in the same time I want to know about SSL connections.
Use Tcp* ans Socket*, not Http* related classes to use really low level in .NET.
TCP is at the bottom of HTTP protocol stack.
Use TCP sockets if you want it to, just use "winsock2.dll" interop calls form c#, and all related stuff like structure definitions etc, or use native C++
Well, if you are building your custom HTTP/HTTPS server or proxy and you don't mind third-party components, then our SecureBlackbox includes HTTP/HTTPS server components which let you do almost anything with any verb. Pure .NET, use any socket classes.
Ok. Again the problem is not in API but in developer :)
I have some test suite to test my implementation but the test suite was connecting directly (not as to a proxy) - that was the first problem. The second problem was that this test suite should use TcpClient instead of HttpWebRequest if I want to test Connect verb separately because HttpWebRequest uses it only internally when using proxy for HTTPS.

SSL without SslStream because I'd like to connect through a SOCKS5 Proxy

BACKGROUND INFORMATION: PROGRAM WRITTEN IN C#
I'm working on a program right now that connects through a SOCKS5 proxy (coded from scratch. works well enough.), but I'd also like to (through that proxy) communicate to a DESTINATION through SSL.
I've done some research, googled many a time, and have come to the conclusion that SslStream won't be ideal for my situation. I NEED to first authenticate with the SSL through the proxy, and THEN start sending encrypted packets, once I receive the key.
QUESTIONS:
How can I encrypt my packets with TLS in C#? For some reason I can't at all figure it out. I'm stuck! :(
What is the raw syntax required to even REQUEST said SSL certificate?
You might want to have a look at the TLS implementation in the open source Bouncy Castle cryptography library. If it won't work as-is, you can hack it into doing what you need. If you want to deep-dive the specification itself, you'll find it as IETF RFC 5246.
As you've probably discovered, though, doing any portion of the connection setup work yourself leaves you with no way to use the WebRequest family of classes to handle the HTTP portion of the protocol work. That leaves you with two options I can see: do the HTTP yourself as well (I found a trivial example HTTP client floating around the net), or change the current user proxy server settings
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings]
"ProxyEnable"=dword:00000001
"ProxyServer"="socks=socks.example.net:1080"
then send the request normally using the WebRequest classes.
I'd like to offer you SSLBlackbox package of our SecureBlackbox product. Among numerous other components it has a simple SSL client component that is socket-based, can connect via different proxies (SOCKS, HTTPS CONNECT) and supports all features of SSL/TLS up to TLS 1.2. If you need more control, you can use any custom socket, and not just built-in socket support. This lets you use the components for securing traffic that goes not via sockets at all (pigeon mail can be secured this way as well).
An HTTPS client is available and included into SSLBlackbox as well.

.NET POP3 Library that supports Proxy

I am looking for a pop3 library that will let me use a proxy. I have tried OpenPop.NET but it doesn't support proxy. Thanks in advance.
I am one of the developers of OpenPop.NET.
I have thought about supporting proxies, but have not added it as of yet. However, the Pop3Client Connect method takes a stream, which it uses to communicate with the server. If you supply a stream, which is a proxied stream, then OpenPop.NET would work fine with it.
I have found a starksoft proxy project that should be able to deliver such streams. I have not tested it though. Also see this for more information on the starksoft proxy.
Hope it helps.
You may try Mail.dll POP3 component. Please note that it's a commercial product that I've created.
It supports HTTP and SOCKS proxies:
http://www.limilabs.com/blog/imap-pop3-smtp-via-http-socks-proxy
I guess there aren't many proxy types able to connect a POP server other than SOCKS.
A quick search on google lead me to this. It allows you to establish a TcpClient connection through a proxy.
Here is the best POP3 client I have ever seen (and used many times), especially if you need to work with the content of retrieved mails. It uses the TcpClient class to establish connections with the POP server and the code is full of comments.
You'll just have to modify the sources (mainly Pop3MailClient) here and there to improve the client so it can use a SOCKS proxy.
Shameless plug:
aspNetPOP3 supports Socks proxy servers.
http://www.aspNetPOP3.com
--Dave

Implementing SSL tunnel in C#

As a part of a larger application I need to implement an SSL tunnel in C#. I was wondering if there's a better way of doing that instead of writing each step of SSL negotiation myself which sounds like reinventing the wheel.
Do you know if there are any libraries that I could use to minimize the code I need to write or any tutorials which show how this or similar thing can be implemented most efficiently in .NET?
SSlStream should do most of the work for you.
It's not clear what you mean by SSL tunnel. If I understand it right, you need some client-side software which acts as a local server (to which other applications connect), this software then connects using SSL to your server-side software, which in turn takes the data out of the SSL tunnel, and routes them further. In this case you would need client-side and server-side SSL/TLS components. You can use our SecureBlackbox for this task. SecureBlackbox provides comprehensive support for SSL/TLS protocol with complete control over connection and certificate management.
It can be that you need not plain SSL channel, but some kind of encrypting proxy. In this case you need to decide what exactly kind of proxy you want (will it be SOCKS proxy or HTTP CONNECT proxy) and implement it on the client side. one of the benefits of such proxy is that it can transfer the real connection address (i.e. where the client wants to go to) to the remote server, and that remote server will perform connection. This is more flexible approach, but it would require some (minimal, I should say) coding to implement the stuff, related to SOCKS or HTTP CONNECT request parsing and response generation.
.NET includes SSL support, centred around the System.Net.Security.SslStream class.

Http tunneling to pass firewall in C# (TCP)

My need is to communicate between 2 client behind NAT using http tunneling. Is it possible? What all setup is needed to achieve this (like http proxy server etc.)? Is there any library or sample code available for implementing http tunneling over TCP in C#?
It might be possible for you to use this library:
http://granados.sourceforge.net/
It supports port forwarding (tunneling in this case),
but I haven't tried it myself.
It's an SSH library... so if you can set up an SSH server on either end of the connection
you'll be able to establish an SSH connection and create a tunnel.

Categories

Resources