Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.

Changed by [EMAIL PROTECTED]

http://bugzilla.ximian.com/show_bug.cgi?id=75687

--- shadow/75687        2005-08-02 08:46:52.000000000 -0400
+++ shadow/75687.tmp.16204      2005-08-02 08:46:52.000000000 -0400
@@ -0,0 +1,136 @@
+Bug#: 75687
+Product: Mono: Class Libraries
+Version: 1.1
+OS: 
+OS Details: ubuntu breezy
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Normal
+Component: Mono.Security
+AssignedTo: [EMAIL PROTECTED]                            
+ReportedBy: [EMAIL PROTECTED]               
+QAContact: [EMAIL PROTECTED]
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: SslClientStream.StartRead() blocks
+
+I tried to use asynchronously SslClientStream. It works properly, except
+that BeginRead() method blocks just like Read(). It makes no difference if
+it's first or fifth read operation afte swiching to TLS.
+
+  Below is sample program that connects to Jabber server, performs TLS
+negotiation and switches to TLS, then writes a space to actually establish
+TLS. There's no "pong" ever printed after call to BeginRead() when no data
+is available for reading.
+
+Program compiles with: mcs -r:Mono.Security.dll test.cs
+Mono.Security.dll version: 1.0.5000.0, Key: 0738eb9f132ed756
+
+using System;
+using System.Text;
+using System.IO;
+using System.Net.Sockets;
+using Mono.Security.Protocol.Tls;
+using Mono.Security.X509;
+using System.Threading;
+
+class MainClass
+{
+
+       const string hostname = "jabber.org.au";
+       const string init =     "<?xml version=\"1.0\"?>\n"+
+               "<stream:stream to=\""+hostname+"\" "+
+               "xmlns=\"jabber:client\" 
xmlns:stream=\"http://etherx.jabber.org/streams\"; "+
+               "version=\"1.0\">";
+       const string starttls =
+               "<starttls xmlns=\"urn:ietf:params:xml:ns:xmpp-tls\"/>";
+
+       const int bufSize = 4096;
+       static byte[] buf = new byte[bufSize];
+       
+       static SslClientStream sslStream;
+       static Stream stream;
+
+       // reads string from stream
+       static string Read()
+    {
+               int x = stream.Read(buf, 0, bufSize);
+               string s = Encoding.UTF8.GetString(buf, 0, x);
+               Console.WriteLine("\nincoming:\n"+s);
+               return s;                
+    }
+    
+    // writes string to stream
+    static void Write(string s)
+    {
+       stream.Write( Encoding.UTF8.GetBytes(s), 0,
+                     Encoding.UTF8.GetByteCount(s) );
+               Console.WriteLine("\noutgoing:\n"+s);
+    }
+
+       private static bool CertificateValidation
+(System.Security.Cryptography.X509Certificates.X509Certificate certificate,
+int[] certificateErrors)
+       {
+               Console.WriteLine("CertificateValidation");             
+               return true; // don't care, always accept
+       }
+
+    public static void DataReceived(IAsyncResult ar)
+    {
+        try {
+            int bytes = stream.EndRead(ar);
+               Console.WriteLine("\nasync
+incoming:\n"+Encoding.UTF8.GetString(buf, 0, bytes));
+        }    
+        catch (Exception e) {
+               Console.WriteLine(e.ToString());
+        }
+    }
+    
+    public static void Main(string[] args)
+       {
+               Mono.Security.Protocol.Tls.SecurityProtocolType protocol = 
+                               
Mono.Security.Protocol.Tls.SecurityProtocolType.Tls;
+               
System.Security.Cryptography.X509Certificates.X509CertificateCollection
+certificates =
+                           new
+System.Security.Cryptography.X509Certificates.X509CertificateCollection ();
+       
+               TcpClient client = new TcpClient();
+               client.Connect(hostname, 5222);
+               stream = client.GetStream();
+
+               // TLS negotiation
+               Write(init); 
+               if (Read().Length < 200) Read();         
+               Write(starttls);
+               Read();
+               
+               Console.WriteLine("\nswitching to TlsClientStream\n");
+               sslStream = new SslClientStream(stream,hostname, true,
+protocol,certificates);
+               sslStream.ServerCertValidationDelegate += new
+CertificateValidationCallback (CertificateValidation);
+               stream = sslStream;
+               
+               // uncommenting this forces server to return some data
+               // Write(init); 
+               
+               Write(" "); // to establish connection
+                               
+               // HERE IS THE PROBLEM
+               Console.WriteLine("ping");
+               try {
+               sslStream.BeginRead(buf, 0, bufSize,
+                                       new AsyncCallback(DataReceived), null );
+               }
+               catch (Exception e) {
+                       Console.WriteLine(e.ToString() );
+               }
+               Console.WriteLine("pong");
+               System.Threading.Thread.Sleep(10000); // wait for async
+       }
+}
_______________________________________________
mono-bugs maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-bugs

Reply via email to