List of usage examples for org.apache.commons.httpclient.contrib.ssl EasyX509TrustManager EasyX509TrustManager
public EasyX509TrustManager(KeyStore keystore) throws NoSuchAlgorithmException, KeyStoreException
From source file:com.hichinaschool.flashcards.async.Connection.java
private Payload doInBackgroundDownloadSharedDeck(Payload data) { String url = (String) data.data[0]; String colFilename = AnkiDroidApp.getCurrentAnkiDroidDirectory() + "/tmpImportFile.apkg"; URL fileUrl;// ww w. j a v a 2 s . c o m URLConnection conn; InputStream cont = null; try { fileUrl = new URL(url); if (url.startsWith("https")) { SSLContext context = SSLContext.getInstance("TLS"); context.init(null, new TrustManager[] { new EasyX509TrustManager(null) }, null); HttpsURLConnection httpsConn = (HttpsURLConnection) fileUrl.openConnection(); httpsConn.setSSLSocketFactory(context.getSocketFactory()); conn = httpsConn; } else { conn = (HttpURLConnection) fileUrl.openConnection(); } conn.setConnectTimeout(10000); conn.setReadTimeout(10000); cont = conn.getInputStream(); } catch (MalformedURLException e) { Log.e(AnkiDroidApp.TAG, "doInBackgroundDownloadSharedDeck: ", e); data.success = false; return data; } catch (IOException e) { Log.e(AnkiDroidApp.TAG, "doInBackgroundDownloadSharedDeck: ", e); data.success = false; return data; } catch (NoSuchAlgorithmException e) { Log.e(AnkiDroidApp.TAG, "doInBackgroundDownloadSharedDeck: ", e); data.success = false; return data; } catch (KeyStoreException e) { Log.e(AnkiDroidApp.TAG, "doInBackgroundDownloadSharedDeck: ", e); return data; } catch (KeyManagementException e) { Log.e(AnkiDroidApp.TAG, "doInBackgroundDownloadSharedDeck: ", e); data.success = false; return data; } if (cont == null) { data.success = false; return data; } File file = new File(colFilename); OutputStream output = null; try { file.createNewFile(); output = new BufferedOutputStream(new FileOutputStream(file)); byte[] buf = new byte[Utils.CHUNK_SIZE]; int len; int count = 0; while ((len = cont.read(buf)) >= 0) { output.write(buf, 0, len); count += len; publishProgress(new Object[] { count / 1024 }); } output.close(); } catch (IOException e) { try { output.close(); } catch (IOException e1) { // do nothing } // no write access or sd card full file.delete(); data.success = false; return data; } data.success = true; data.result = colFilename; return data; }
From source file:org.apache.commons.httpclient.contrib.ssl.EasySSLProtocolSocketFactory.java
private static SSLContext createEasySSLContext() { try {/* www .j a v a 2s . c o m*/ SSLContext context = SSLContext.getInstance("SSL"); context.init(null, new TrustManager[] { new EasyX509TrustManager(null) }, null); return context; } catch (Exception e) { LOG.error(e.getMessage(), e); throw new RuntimeException(e.toString()); } }