Beispiel #1
0
  private searchMenuMgr() {

    try {
      KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
      trustStore.load(null, null);
      MySSLSocketFactory socketFactory = new MySSLSocketFactory(trustStore);
      socketFactory.setHostnameVerifier(MySSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
      client = new AsyncHttpClient();
      client.setSSLSocketFactory(socketFactory);
      client.setCookieStore(new PersistentCookieStore(Login_Main.getContext()));
      client.setTimeout(10000);
    } catch (KeyStoreException e) {
      e.printStackTrace();
    } catch (NoSuchAlgorithmException e) {
      e.printStackTrace();
    } catch (CertificateException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    } catch (KeyManagementException e) {
      e.printStackTrace();
    } catch (UnrecoverableKeyException e) {
      e.printStackTrace();
    }
  }
 public static org.apache.http.conn.ssl.SSLSocketFactory getFixedSocketFactory()
 {
   try
   {
     MySSLSocketFactory localMySSLSocketFactory = new MySSLSocketFactory(getKeystore());
     localMySSLSocketFactory.setHostnameVerifier(org.apache.http.conn.ssl.SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
     return localMySSLSocketFactory;
   }
   catch (Throwable localThrowable)
   {
     localThrowable.printStackTrace();
   }
   return org.apache.http.conn.ssl.SSLSocketFactory.getSocketFactory();
 }
  /**
   * Returns default instance of SchemeRegistry
   *
   * @param fixNoHttpResponseException Whether to fix or not issue, by ommiting SSL verification
   * @param httpPort HTTP port to be used, must be greater than 0
   * @param httpsPort HTTPS port to be used, must be greater than 0
   */
  private static SchemeRegistry getDefaultSchemeRegistry(
      boolean fixNoHttpResponseException, int httpPort, int httpsPort) {
    if (fixNoHttpResponseException) {
      Log.d(LOG_TAG, "Beware! Using the fix is insecure, as it doesn't verify SSL certificates.");
    }

    if (httpPort < 1) {
      httpPort = 80;
      Log.d(LOG_TAG, "Invalid HTTP port number specified, defaulting to 80");
    }

    if (httpsPort < 1) {
      httpsPort = 443;
      Log.d(LOG_TAG, "Invalid HTTPS port number specified, defaulting to 443");
    }

    // Fix to SSL flaw in API < ICS
    // See https://code.google.com/p/android/issues/detail?id=13117
    SSLSocketFactory sslSocketFactory;
    if (fixNoHttpResponseException) sslSocketFactory = MySSLSocketFactory.getFixedSocketFactory();
    else sslSocketFactory = SSLSocketFactory.getSocketFactory();

    SchemeRegistry schemeRegistry = new SchemeRegistry();
    schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), httpPort));
    schemeRegistry.register(new Scheme("https", sslSocketFactory, httpsPort));

    return schemeRegistry;
  }