<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Sample Asynchronous SslStream Client/Server Implementation</title><link>http://blogs.msdn.com/joncole/archive/2007/06/13/sample-asynchronous-sslstream-client-server-implementation.aspx</link><description>I was recently asked about sample code for the System.Net.Security.SslStream using the asynchronous APIs. I searched the web and couldn't find anything significant, so I decided to write some that included the asynchronous usage of the TcpListenter and</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>Servidor y cliente TCP SSL as??ncrono. &amp;laquo; vtortola.Net</title><link>http://blogs.msdn.com/joncole/archive/2007/06/13/sample-asynchronous-sslstream-client-server-implementation.aspx#3453488</link><pubDate>Fri, 22 Jun 2007 08:58:44 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:3453488</guid><dc:creator>Servidor y cliente TCP SSL as??ncrono. « vtortola.Net</dc:creator><description>&lt;p&gt;PingBack from &lt;a rel="nofollow" target="_new" href="http://vtortola.wordpress.com/2007/06/22/servidor-y-cliente-tcp-ssl-asincrono/"&gt;http://vtortola.wordpress.com/2007/06/22/servidor-y-cliente-tcp-ssl-asincrono/&lt;/a&gt;&lt;/p&gt;
</description></item><item><title>re: Sample Asynchronous SslStream Client/Server Implementation</title><link>http://blogs.msdn.com/joncole/archive/2007/06/13/sample-asynchronous-sslstream-client-server-implementation.aspx#4069405</link><pubDate>Thu, 26 Jul 2007 21:22:46 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:4069405</guid><dc:creator>Chris Mullins</dc:creator><description>&lt;P&gt;Our XMPP SDK makes extensive (!) use of the SSLStream class and does so using the Async infrastructure. &lt;/P&gt;
&lt;P&gt;We ran into trouble with the threading requirements around the stream - the inability of the stream to queue Async writes was a bit frustrating, and we ended up having to wrap it in a BufferedStream that did properly queue aync writes and did all the appropiate blocking to insure the SSLStream didn't have threading issues. &lt;/P&gt;</description></item><item><title>Encrypting Passwords</title><link>http://blogs.msdn.com/joncole/archive/2007/06/13/sample-asynchronous-sslstream-client-server-implementation.aspx#5716724</link><pubDate>Sat, 27 Oct 2007 21:24:13 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:5716724</guid><dc:creator>Ken J.</dc:creator><description>&lt;P&gt;None of the data in my program needs to be encrypted except the username and password when the client connects. I don't know anything about certificates and I'm finding all these examples to be complex. I spent 2 weeks writing some network classes using System.Net.Sockets.Socket. Is there a way I can send the username and password over a secure connection, and then once the client is validated, move back to an unsecure connection? My server is a game server and if I encrypted everything on my game server with sslStream it would be an extrem load on my server.&lt;/P&gt;</description></item><item><title>re: Sample Asynchronous SslStream Client/Server Implementation</title><link>http://blogs.msdn.com/joncole/archive/2007/06/13/sample-asynchronous-sslstream-client-server-implementation.aspx#7134464</link><pubDate>Wed, 16 Jan 2008 23:37:55 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:7134464</guid><dc:creator>joncole</dc:creator><description>&lt;p&gt;Yes, you can switch back to an unsecure connection once you have finished transfering the username and password. &amp;nbsp;You will need to do the following:&lt;/p&gt;
&lt;p&gt;1) When you create the SslStream, make sure to pass in true for the leaveInnerStreamOpen paramenter to the constructor. &amp;nbsp;&lt;/p&gt;
&lt;p&gt;2) Make sure to hold onto a reference to the inner stream (the NetworkStream object).&lt;/p&gt;
&lt;p&gt;3) Close the SslStream object and start using the NetworkStream object again.&lt;/p&gt;
&lt;p&gt;As for certificates, you can contact one of the many certificate venders (like Verisign) to buy a server certificate. &amp;nbsp;&lt;/p&gt;
</description></item><item><title>re: Sample Asynchronous SslStream Client/Server Implementation</title><link>http://blogs.msdn.com/joncole/archive/2007/06/13/sample-asynchronous-sslstream-client-server-implementation.aspx#8327452</link><pubDate>Thu, 20 Mar 2008 17:56:40 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8327452</guid><dc:creator>Tom L</dc:creator><description>&lt;p&gt;What should I use for the parameter targetHost in StartConnecting? &amp;nbsp;It doesn't seem to matter what value I have for it, just as long as I have *something*. &amp;nbsp;How/why is that targetHost used?&lt;/p&gt;
&lt;p&gt;TYIA&lt;/p&gt;</description></item><item><title>re: Sample Asynchronous SslStream Client/Server Implementation</title><link>http://blogs.msdn.com/joncole/archive/2007/06/13/sample-asynchronous-sslstream-client-server-implementation.aspx#8409221</link><pubDate>Sat, 19 Apr 2008 01:18:36 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8409221</guid><dc:creator>joncole</dc:creator><description>&lt;P&gt;The remoteHostName (aka targetHost) is the name of the server to which you are connecting. &amp;nbsp;It should match the name on the server's certificate. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;As a&amp;nbsp;test to make sure that I remembered this correctly (I&amp;nbsp;haven't used SslStream for a while), I&amp;nbsp;created a test cert&amp;nbsp;with the subject on the&amp;nbsp;cert something other than "localhost" like "myMachineName".&amp;nbsp; &amp;nbsp;If I passed in anything other than "myMachineName" for the remoteHostName parameter, then I started getting the "RemoteCertificateNameMismatch" certificate error. &lt;/P&gt;
&lt;P&gt;It probably works with any value for you because in my sample code above I am using the IgnoreCertificateErrorsCallback method as my certificate error validation routine. &amp;nbsp;This sample validation routine ignores certificate errors - I use this in testing, but in real life you should implement your own routine based on your security needs/policies.&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;Also, having been away from this for a while, I realized that I couldn't remember the exact command line I used to create my test certificate.&amp;nbsp; After fiddling with it a while to get it right, I ended up using &lt;STRONG&gt;&lt;EM&gt;makecert -r -pe -n "CN=localhost" -m 12 -sky exchange -ss my serverCert.cer&lt;/EM&gt;&lt;/STRONG&gt;.&amp;nbsp; This command created a self-signed certificate with "localhost" for the certificate subject and it makes the certificate valid for 12 months.&lt;/P&gt;
&lt;P&gt;Hope that helps.&lt;/P&gt;</description></item><item><title>re: Sample Asynchronous SslStream Client/Server Implementation</title><link>http://blogs.msdn.com/joncole/archive/2007/06/13/sample-asynchronous-sslstream-client-server-implementation.aspx#9529307</link><pubDate>Thu, 02 Apr 2009 18:36:49 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9529307</guid><dc:creator>Alan McF</dc:creator><description>&lt;P&gt;Many thanks for the makecert command-line. &amp;nbsp;I've been trying to create an acceptable certificate (with PrivateKey!!) for hours!&lt;/P&gt;
&lt;P&gt;Alan&lt;/P&gt;</description></item><item><title>re: Sample Asynchronous SslStream Client/Server Implementation</title><link>http://blogs.msdn.com/joncole/archive/2007/06/13/sample-asynchronous-sslstream-client-server-implementation.aspx#9880865</link><pubDate>Sat, 22 Aug 2009 23:23:49 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9880865</guid><dc:creator>Kiotaya Rotan</dc:creator><description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I am new to C# and sockets. I found this tutorial easy to follow and full of great information. I was able to get it working rather quickly. I have had some problems with sending more data (another string) through the secured stream. &lt;/P&gt;
&lt;P&gt;After the connection to the server is made and authenticated, a hello from the client is sent and a hello is sent from the server and received at the client. After this exchange, how do I send more data (another string) through the secure stream? &lt;/P&gt;
&lt;P&gt;Thanks in advance for your response.&lt;/P&gt;
&lt;P&gt;Kio&lt;/P&gt;
&lt;P&gt;kiotaya@yahoo.com&lt;/P&gt;</description></item><item><title>re: Sample Asynchronous SslStream Client/Server Implementation</title><link>http://blogs.msdn.com/joncole/archive/2007/06/13/sample-asynchronous-sslstream-client-server-implementation.aspx#9897766</link><pubDate>Tue, 22 Sep 2009 01:13:53 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9897766</guid><dc:creator>joncole</dc:creator><description>&lt;p&gt;I can only guess with the limited information I have, but are you calling &amp;quot;WriteLine&amp;quot; or &amp;quot;Write&amp;quot; on the StreamWriter instance? &amp;nbsp;The sample code I have provided uses StreamReader and StreamWriter in conjunction with WriteLine/ReadLine. &amp;nbsp;If you accidentally use &amp;quot;Write&amp;quot; instead of WriteLine, then the other side of the connection will block, waiting for the end of the line in the string. &amp;nbsp;You may want to read my post on &amp;quot;Simple Message Framing Sample for TCP Socket&amp;quot; (or the asynchronous counterpart that follows).&lt;/p&gt;
</description></item></channel></rss>