Upgrade to SSL using StreamSocket

1

I am working on WinRT(Windows8 Release Preview). I have a web application(in fact, a simpler XMPP Client).

I mainly use StreamSocket class to connect the Jabber Server. It gives me a good start.But I met a problem when i try to upgrade the already connected socket to use SSL.

I use StreamSocket.UpgradeToSslAsync to implement it. It throws exception like this

A method was called at an unexpected time. (Exception from HRESULT: 0x8000000E)

I have no idea why this happen. I have done all thing as the above link. I have created the socket connecting successfully. And I can receive some xml stanzas from Jabber server. Here is a picture when it runs.![enter image description here][1]

You can see the picture in a new tab.

When I click the UpToSSL button, it crashes and throw the exception as above.

Here is simpler version code:

 // xmpp is my  CXMPP  client class
 private void StartTlsBtn_Click(object sender, RoutedEventArgs e)
 {
   xmpp.SendXml("<starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls' />");            
 } 
 // it works fine, and i have got the reponse from server:
 //     <proceed xmlns='urn:ietf:params:xml:ns:xmpp-tls'/>
 // next step i should upgrade my sockey connection to ssl

    private void UpSslBtn_Click(object sender, RoutedEventArgs e)
    {
      xmpp.UpToSsl();         
    }

    async public void UpToSsl()
    {
        SendEvent.WaitOne();
        SendEvent.Reset();

        // private StreamSocket ClientSock;
        await ClientSock.UpgradeToSslAsync(SocketProtectionLevel.Ssl, ClientSock.Information.RemoteHostName);
        isSsl = true;
        SendEvent.Set();
    }  

Please give me some tips. Thank you.

c#
ssl
xmpp
windows-runtime
microsoft-metro
asked on Stack Overflow Jun 15, 2012 by zjalex • edited Jun 15, 2012 by zjalex

1 Answer

1

I am working on an XMPP application for Metro as well, the server connection and the protocol parser are ready.

I am using three ManualResetEvents so Send, Receive and Elevate won't collide. Also be carefull as UpgradeToSslAsync dosn't accept self-signed certificates, and in that case will throw an exception.

I would really like to help you further but I try to finance myself with this, the XMPP library will be released after the application is released in the store

answered on Stack Overflow Jun 17, 2012 by PaulFreund

User contributions licensed under CC BY-SA 3.0