1 Reply Latest reply on Jun 1, 2013 12:30 AM by Jaron Smith

    TCPSocket.open() fails on Windows Mobile

      TCPSocket.open() fails on Windows Mobile with error:

         E 02/04/2013 15:48:30:000 8e79d9f6              RubyVM| lib/net/http.rb:658:  [BUG]

         E 02/04/2013 15:48:30:000 8e79d9f6              RubyVM| rb_sys_fail(socket(2)) - errno == 0

       

      I tried many approaches that gave the same results, but these two sum up the problem being in the TCPSocket.open() call.

      I am trying to perform an HTTPS request with X509 certificates. I am successful when I use the RhoSimulator but fail on the MC9190 Windows Mobile device.

       

      METHOD 1:

               myPemFile = "/temp/server.pem"

               pem = File.read myPemFile

       

               myCertFile = "/temp/server.crt"

               myCert = File.read myCertFile

               certificate = OpenSSL::X509::Certificate.new myCert

       

               myKeyFile = "/temp/server.key"

               rawKey = File.read myKeyFile

               myKey = OpenSSL::PKey::RSA.new rawKey

       

               store = OpenSSL::X509::Store.new

               store.set_default_paths

       

               ssl_context = OpenSSL::SSL::SSLContext.new

               ssl_context.cert_store = store

               ssl_context.verify_mode = OpenSSL::SSL::VERIFY_NONE

               ssl_context.ssl_version = :TLSv1

               ssl_context.cert = certificate

               ssl_context.key = myKey

               ssl_context.ca_file = pem

       

               MyLogger("mec madit at,,,666 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~")  ##### <-- NOTE: This does print

       

               host = www.google.com

               port = 443

               open_timeout = nil

               socket = timeout(open_timeout) { TCPSocket.open(host, port) }  ##### <--- LINE 648 of http.rb

       

               MyLogger("mec madit AWESOME - MADIT!!!!  777 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~") ##### <-- NOTE: This does NOT print

       

      Method 1 output:

      I 02/05/2013 14:48:48:000 edca6bba APP InventoryController| MEC_LOG: (mec madit at,,,666 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~)

      E 02/05/2013 14:48:49:000 edca6bba              RubyVM| apps/app/Inventory/inventory_controller.rb:353:  [BUG]

      E 02/05/2013 14:48:49:000 edca6bba              RubyVM| rb_sys_fail(socket(2)) - errno == 0

      E 02/05/2013 14:48:49:000 edca6bba              RubyVM| Description: ruby 1.9.2p290 (2011-07-09) [i386-mswin32_80]

      E 02/05/2013 14:48:49:000 edca6bba              RubyVM| -- control frame ----------

      E 02/05/2013 14:48:49:000 edca6bba              RubyVM| ---------------------------

      E 02/05/2013 14:48:49:000 edca6bba              RubyVM| -- Ruby level backtrace information ----------------------------------------

      E 02/05/2013 14:48:49:000 edca6bba              RubyVM| lib/rho/rho.rb:883:in `serve'

      E 02/05/2013 14:48:49:000 edca6bba              RubyVM| lib/rho/rhoapplication.rb:248:in `serve'

      E 02/05/2013 14:48:49:000 edca6bba              RubyVM| lib/rho/rhocontroller.rb:104:in `serve'

      E 02/05/2013 14:48:49:000 edca6bba              RubyVM| apps/app/Inventory/inventory_controller.rb:353:in `getInventoryCount'

      E 02/05/2013 14:48:49:000 edca6bba              RubyVM| lib/timeout.rb:88:in `timeout'

      E 02/05/2013 14:48:49:000 edca6bba              RubyVM| lib/timeout.rb:44:in `timeout'

      E 02/05/2013 14:48:49:000 edca6bba              RubyVM| apps/app/Inventory/inventory_controller.rb:353:in `block in getInventoryCount'

      E 02/05/2013 14:48:49:000 edca6bba              RubyVM| apps/app/Inventory/inventory_controller.rb:353:in `open'

      E 02/05/2013 14:48:49:000 edca6bba              RubyVM| apps/app/Inventory/inventory_controller.rb:353:in `initialize'

       

      METHOD 2:

             url = URI.parse "http://www.google.com/"

             http = Net::HTTP.new(url.host, url.port)

             http.use_ssl = (url.scheme == 'https')

             http.ssl_version = :TLSv1

             http.ca_file = pem

             http.cert = certificate

             http.key = myKey

             http.verify_mode = OpenSSL::SSL::VERIFY_PEER

             request = Net::HTTP::Get.new(url.path)

             response = http.request(request) ##### <-- NOTE: This does NOT execute, but calls HTTP.RB connect() below:

       

      http.rb snippet (C:\MotorolaRhoMobileSuite2.2.1.12\ruby\lib\ruby\gems\1.9.1\gems\rhodes-3.5.1.12\lib\extensions\net-http\net):

      654    def connect

      655      platform = System::get_property('platform')

      656      if !(use_ssl? and platform == 'Blackberry')

      657        D "opening connection to #{conn_address()}..."

      658        s = timeout(@open_timeout) { TCPSocket.open(conn_address(), conn_port()) }  ##### <--- LINE 648 of http.rb

      659        D "opened"

      660      end

       

      Method 2 Output:

      E 02/04/2013 15:48:30:000 8e79d9f6              RubyVM| lib/net/http.rb:658:  [BUG]

      E 02/04/2013 15:48:30:000 8e79d9f6              RubyVM| rb_sys_fail(socket(2)) - errno == 0

      E 02/04/2013 15:48:30:000 8e79d9f6              RubyVM| Description: ruby 1.9.2p290 (2011-07-09) [i386-mswin32_80]

      E 02/04/2013 15:48:30:000 8e79d9f6              RubyVM| -- control frame ----------

      E 02/04/2013 15:48:30:000 8e79d9f6              RubyVM| ---------------------------

      E 02/04/2013 15:48:30:000 8e79d9f6              RubyVM| -- Ruby level backtrace information ----------------------------------------

      E 02/04/2013 15:48:30:000 8e79d9f6              RubyVM| lib/rho/rho.rb:883:in `serve'

      E 02/04/2013 15:48:30:000 8e79d9f6              RubyVM| lib/rho/rhoapplication.rb:248:in `serve'

      E 02/04/2013 15:48:30:000 8e79d9f6              RubyVM| lib/rho/rhocontroller.rb:104:in `serve'

      E 02/04/2013 15:48:30:000 8e79d9f6              RubyVM| apps/app/Inventory/inventory_controller.rb:241:in `getInventoryCount'

      E 02/04/2013 15:48:30:000 8e79d9f6              RubyVM| lib/net/http.rb:1189:in `request'

      E 02/04/2013 15:48:30:000 8e79d9f6              RubyVM| lib/net/http.rb:638:in `start'

      E 02/04/2013 15:48:30:000 8e79d9f6              RubyVM| lib/net/http.rb:649:in `do_start'

      E 02/04/2013 15:48:30:000 8e79d9f6              RubyVM| lib/net/http.rb:658:in `connect

      ' E 02/04/2013 15:48:30:000 8e79d9f6              RubyVM| lib/timeout.rb:88:in `timeout'

      E 02/04/2013 15:48:30:000 8e79d9f6              RubyVM| lib/timeout.rb:44:in `timeout'

      E 02/04/2013 15:48:30:000 8e79d9f6              RubyVM| lib/net/http.rb:658:in `block in connect'

      E 02/04/2013 15:48:30:000 8e79d9f6              RubyVM| lib/net/http.rb:658:in `open'

      E 02/04/2013 15:48:30:000 8e79d9f6              RubyVM| lib/net/http.rb:658:in `initialize'

       

      my.rb 'require' code snippet:

         require 'rho/rhocontroller'

         require 'helpers/browser_helper'

         require 'openssl'

         require 'net/http'

         require 'net/https'

         require 'socket'

         require 'uri'

       

      build.yml snippet:

      wm:

         sdk: "Windows Mobile 6 Professional SDK (ARMV4I)"

      extensions:

         - json

         - another-extension

         - digest

         - digest-md5

         - digest-sha1

         - digest-sha2

         - openssl.so

         - openssl

         - ezcrypto

         - net-http

         - uri

         - timeout

         - thread

         - zlib

         - net-https

         - socket

         - tcpsocket

         - fcntl

      capabilities:

         - motorola_browser

       

      What am I missing? 

      Is TCPSocket() supported by RhoMobile on Windows Mobile?