2014-01-16 35 views
2

我正在爲Android開發AIR(Flex)移動應用程序,並且需要使用SSL或TSL與http服務器進行通信。我使用的是Firefox的CA證書鏈(與其他工具檢查也),並得到了以下鏈:我的AIR移動應用程序正在忽略Android證書商店

enter image description here

的一個劃痕是我公司的SSL/TSL服務器。出於安全原因,我不希望發佈其地址。 因此,在找出我需要的證書(鏈中只有兩個)之後,我在Android平板電腦上搜索了安裝的哪些證書。正如你可以在接下來的畫面中,根證書看,「威瑞信3級公用主證書頒發機構 - G5」已經安裝在系統上:

enter image description here

,我需要下載的唯一一個是「威瑞信3級安全服務器CA - G3」 ,這是我已經做了:

enter image description here

現在,我嘗試進入到HTTP服務器有兩個不同的瀏覽器,我不再接受任何證書要求。 AIR進入場景時出現問題。我嘗試了兩種使用HTTPService和SecureSocket與服務器通信的方法。 對於第一個我用下面的代碼:

<s:View xmlns:fx="http://ns.adobe.com/mxml/2009" 
     xmlns:s="library://ns.adobe.com/flex/spark" 
     title="HomeView"> 

    <fx:Declarations> 
     <s:HTTPService id="bookingservice" 
         resultFormat="text" 
         url="https://www.myserver.com/" 
         result="bookingservice_resultHandler(event)" 
         fault="bookingservice_faultHandler(event)"/> 
    </fx:Declarations> 

    <fx:Script> 
     <![CDATA[ 
      import mx.rpc.events.FaultEvent; 
      import mx.rpc.events.ResultEvent; 

      protected function button1_clickHandler(event:MouseEvent):void 
      { 
       resultado.text = "llamando..."; 
       bookingservice.send(); 
      } 
      protected function bookingservice_resultHandler(event:ResultEvent):void 
      { 
       resultado.text = event.result as String; 
      } 

      protected function bookingservice_faultHandler(event:FaultEvent):void 
      { 
       resultado.text = "satus code: " + event.statusCode + " mensaje: " + event.message.toString(); 
      } 
     ]]> 
    </fx:Script> 

    <s:Button top="10" right="10" click="button1_clickHandler(event)" label="Extra" /> 

    <s:TextArea id="resultado" 
       width="80%" height="80%" 
       horizontalCenter="0" verticalCenter="0" /> 

</s:View> 

這令人難以置信的簡單方法有一個消息框,要求用戶接受,即使所有的證書鏈安裝在Android的系統證書存儲區未驗證的服務器端。 因爲我使用下面的代碼第二種方法:

<s:View xmlns:fx="http://ns.adobe.com/mxml/2009" 
     xmlns:s="library://ns.adobe.com/flex/spark" 
     title="HomeView"> 

    <fx:Script> 
     <![CDATA[ 

      private var secureSocket:SecureSocket = new SecureSocket; 

      protected function button1_clickHandler(event:MouseEvent):void 
      { 
       secureSocket.addEventListener(Event.CONNECT, onConnect) 
       secureSocket.addEventListener(IOErrorEvent.IO_ERROR, onError); 

       resultado.text = "llamando..."; 
       try 
       { 
        secureSocket.connect("https://www.myserver.com/",443); 
       } 
       catch (error:Error) 
       { 
        trace (error.toString()); 
       } 

       resultado.text = "llamando..."; 
      } 
      private function onConnect(event:Event):void 
      { 
       resultado.text = "Connected."; 
      } 

      private function onError(error:IOErrorEvent):void 
      { 
       resultado.text = error.text + ", Server Certificate Status: " + secureSocket.serverCertificateStatus; 
      } 

     ]]> 
    </fx:Script> 

    <s:Button top="10" right="10" click="button1_clickHandler(event)" label="Extra" /> 

    <s:TextArea id="resultado" 
       width="80%" height="80%" 
       horizontalCenter="0" verticalCenter="0" /> 

</s:View> 

對於這最後的辦法,我甚至不得到一個消息框,詢問證書的授權,我只得到它說的錯誤:「錯誤#2031:套接字錯誤。 URL:https://www.myserver.com/,服務器證書狀態:無效「。 我想知道爲什麼AIR(Flex)移動運行時不考慮已在Android證書存儲中安裝的證書,並且它仍在要求用戶授權,或者甚至要求提供錯誤並指出服務器證書無效。有誰知道爲什麼會發生這種情況?我錯過了什麼嗎?

每一位的幫助將不勝感激。

+0

而不是'www.myserver.com'你也嘗試過'myserver.com'嗎? –

+0

@AlexanderFarber,'www.myserver.com'只是一個例子,實際上,這個域名是'something.myserver.com'。 – SebastianT

回答

0

不是一個真正的答案,但對於SecureSocket -

you can add your own certificates programmatically with the addBinaryChainBuildingCertificate() method

+0

[SecureSocket]的文檔(http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/SecureSocket。html)類沒有解釋如何使用'addBinaryChainBuildingCertificate()'。你有任何想法如何使用紅外? – SebastianT

+0

我下載了三個證書中的每一個,將它們轉換成DER格式(Firefox將它們導出爲PEM),然後將它們全部3個添加到套接字'addBinaryChainBuildingCertificate()'中,我甚至沒有使用該方法發生錯誤(如果證書的格式不正確),仍然是相同的錯誤:'「錯誤#2031:套接字錯誤。 URL:https://www.myserver.com/,服務器證書狀態:無效「'。你有更多的線索嗎? – SebastianT

0

簡單地改變

secureSocket.connect(" https://www.myserver.com/ ",443);

secureSocket.connect("www.myserver.com",443);

(假設 「www.myserver.com」 是域在證書中命名)

相關問題