1 Reply Latest reply on Mar 15, 2011 6:04 AM by dishmael3

    ActionScript 3.0, Sockets and SecureSockets


      Greetings everyone,


      I am trying to write an AIR application that communicates with a legacy system via Socket and SecureSocket. The legacy system leverages the handshake mechanism found in XMPP (RFC 3920). Unfortunately, the legacy system only uses the protocol setup and not the actual messaging mechanisms. Thus I need to create my own wrapper for setting up the connection. Basically I need to do the following:


      1. Connect to the remote system using Socket("my.remote.system", 6482)
      2. Start communication stream, wait for proceed response from server
      3. Switch to TLS/SSL (SecureSocket) on the existing connection from Step 1 above
      4. Authenticate using SASL, wait for success response from server
      5. Send custom messages to remote system


      I have the first two steps working but I cannot seem to figure out how to convert an existing connection to use TLS/SSL.

        • 1. Re: ActionScript 3.0, Sockets and SecureSockets
          dishmael3 Level 1

          FWIW, the following is a snippet of working C++ code using the OpenSSL library:



          /* Socket descriptor */
          int sockfd;
          /* Perform initial connection; omitted for brevity */
          connect( ... );
          /* Initialize the SSL library */
          /* Setup the SSL context */
          SSL_CTX *ssl_ctx = SSL_CTX_new(SSLv23_client_method());
          if (ssl_ctx == NULL) {
               // TODO: deal with error
          /* Allocate the SSL pointer (REUSE EXISTING SOCKET FD) */
          SSL *ssl = SSL_new(ssl_ctx);
          if (SSL_set_fd(ssl, sockfd) != 1) {
               // TODO: deal with error
          /* Set SSL modes */
          SSL_set_mode( ssl, SSL_MODE_AUTO_RETRY 
          /* Transition to SSL */
          if (SSL_connect(ssl) != 1) {
               // TODO: deal with error
          /* We successfully connected */
          printf("Transition to SSL successful\n");



          As you can see above, I set the existing file descriptor for the socket in the SSL pointer: SSL_set_fd(ssl, sockfd). This allows me to transition to SSL using an existing connection. Is this possible with the ActionScript 3.0 Socket and SecureSocket?