2013-02-21 478 views
1

我使用自簽名證書的主機。所以我從我的域名https://www.marpel.cz/下載了證書,並使用http://portecle.sourceforge.net/創建了.bks文件。自簽名證書

我需要建立https連接並從我的web服務中檢索數據。我使用kso​​ap2庫。我已複製並使用kso​​ap2 wiki中陳述的類ConnectionWithSelfSignedCertificate

這是我創建密鑰庫

MainActivity.java 
    // Get an instance of the Bouncy Castle KeyStore format 
    try { 
     this.keyStore = KeyStore.getInstance("BKS"); 
    } catch (KeyStoreException e1) { 
     // TODO Auto-generated catch block 
     e1.printStackTrace(); 
    } 
    // Get the raw resource, which contains the keystore with 
    // your trusted certificates (root and any intermediate certs) 
    InputStream in = this.getApplicationContext().getResources().openRawResource(R.raw.myCer); 
    try { 
     // Initialize the keystore with the provided trusted certificates 
     // Also provide the password of the keystore 
     this.keyStore.load(in, "myPass".toCharArray()); 
    } catch (Exception e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    }finally { 
     try { 
      in.close(); 
     } catch (IOException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } 
    } 

    try { 
     this.sslSocketFactory = new ConnectionWithSelfSignedCertificate(this.keyStore).getSSLSocketFactory(); 
    } catch (Exception e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } 

的方式,這是從的AsyncTask

background task 
final HttpsTransportSE transportSE = new HttpsTransportSE(URL, PORT, SERVICE, TIMEOUT); 

    try { 
     ((HttpsServiceConnectionSE) transportSE.getServiceConnection()).setSSLSocketFactory(this.sslSocketFactory); 
    } catch (IOException e1) { 
     // TODO Auto-generated catch block 
     e1.printStackTrace(); 
    } 

如果我打電話transportSE.call(SOAP_ACTION,信封)代碼;我得到IOException,主機名'www.marpel.cz'未被驗證。我做錯了什麼?

我有一個ICS 4.1.2設備。

回答

0

首先,你使用自簽名證書嗎?

如果是,那麼請點擊此鏈接:android-webservices-via-ksoap2-https

你需要創建HTTPS連接,並接受證書的額外的類。一切準備就緒後,您可以致電transportSE

0

我的第一篇文章中的代碼正常工作。我發現自簽名證書是針對不同的域頒發的。我修復了證書,一切正常。

固定證書這裏https://www.marpel.cz:445/

運行謝謝,馬丁。