0 Replies Latest reply on Dec 28, 2010 7:09 AM by Ali_Hasan

    SecureSocket connection issue

    Ali_Hasan

      I am trying to connect my AIR app (desktop)  to xmpp server using SecureSocket but it fails with this error

      Error #2031: Socket Error. URL: xxxx.xxxx.xxxx.xxxxxx

      socket.serverCertificateStatus = invalid.

      On further investigation it boiled down to this
      Error #2048: Security sandbox violation: app:/TlsTest2.swf  cannot load data from  xxxx.xxxx.xxxx.xxxxxx:5222.
      But the app connects and works smoothly with plain binary socket.
      I have gone through these steps for secure communication test.
      1. Created own Certificate Authority using openssl  as myCA
      2. Signed a xmpp server(with its ip) security certificate with the myCA and installed on xmpp server.
      3. Installed myCA on the test machine(windows xp sp2) as a trusted root certificate authority.
      4. Ran the sample to connect to server using both plain binary socket and SecureSocket.
      plain binary socket just works fine but SecureSocket connection fails
      non-AIR client works fine on secure connection with the xmpp server.
      code:
      <?xml version="1.0" encoding="utf-8"?>
      <s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009" 
                                  xmlns:s="library://ns.adobe.com/flex/spark" 
                                  xmlns:mx="library://ns.adobe.com/flex/mx" creationComplete="windowedapplication1_creationCompleteHandler(event)">
           <fx:Script>
                <![CDATA[
                     import mx.events.FlexEvent;
                     private var socket:SecureSocket;//Socket;
                     private var psocket:Socket;
                     protected function windowedapplication1_creationCompleteHandler(event:FlexEvent):void
                     {
                          socket = new SecureSocket(); //new Socket();//
                          socket.addEventListener(Event.CONNECT , onConnected , false , 0, true );
                          socket.addEventListener(IOErrorEvent.IO_ERROR ,onError , false , 0 ,true );
                          trace("secure socket supported:" + SecureSocket.isSupported );
                          
                          psocket = new Socket();
                          psocket.addEventListener(Event.CONNECT , onPSocketConnected , false , 0 ,true );
                          psocket.addEventListener(IOErrorEvent.IO_ERROR , onPSocketError ,false , 0 , true );
                          try {
                               socket.connect("xxx.xx.xxx.xx" , 5222 );
                               psocket.connect( "xxx.xx.xxx.xx" , 5222 );
                               trace("connecting...");
                          } catch ( error:Error ) {
                               trace( error.toString() );
                          }
                     }
                     
                     private function onConnected(event:Event):void {
                          trace("connected");
                     }
                     
                     private function onError(error:IOErrorEvent):void {
                          trace( error.text + ", "+ socket.serverCertificateStatus );
                     }
      
                     
                     private function onPSocketConnected(event:Event):void {
                          message.text = "Plain socket connected";
                     }
                     
                     private function onPSocketError(event:IOErrorEvent):void {
                          message.text = "Plain socket error:"+ event.text;
                     }
                ]]>
           </fx:Script>
           <fx:Declarations>
                <!-- Place non-visual elements (e.g., services, value objects) here -->
           </fx:Declarations>
           <s:Label x="160" y="197" width="346" id="message"/>
      </s:WindowedApplication>