屏蔽HTTPS证书验证下载apk安装包
来源:互联网 发布:淘宝宝贝描述图片宽度 编辑:程序博客网 时间:2024/05/21 17:28
当我们从一个HTTPS的网址下载资源时,不需要经过它的证书验证实现下载想要的资源
private void DownApk(String url) throws MalformedURLException { String urlStr=url; try {
// 目前的证书基本都是ca签名验证,SSL验证。
SSLContext sc =SSLContext.getInstance("TLS"); sc.init(null, new TrustManager[]{new MyTrustManager()}, new SecureRandom());// HttpsURLConnection 验证,不是 HttpURLConnection
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); HttpsURLConnection.setDefaultHostnameVerifier(new MyHostnameVerifier()); HttpsURLConnection conn = (HttpsURLConnection)new URL(urlStr).openConnection(); conn.setDoOutput(true); conn.setDoInput(true);
// 上面代码就可以做到屏蔽HTTPS的证书,从而实现通畅的下载资源。
// 删除文件夹 File apkfile = new File("/sdcard/xxx.apk"); if (apkfile.exists()){ apkfile.delete(); } final String fileName = "xxx.apk"; File tmpFile = new File("/sdcard/"); if (!tmpFile.exists()) { tmpFile.mkdir(); } downapkfile = new File("/sdcard/1jindianzi", fileName); try { downapkfile.createNewFile(); } catch (IOException e) { e.printStackTrace(); } InputStream is = conn.getInputStream(); //内容总长度 long contentlength = conn.getContentLength(); //已下载的长度 long loadedlength = 0; System.out.println(contentlength+""); FileOutputStream fileOutput= new FileOutputStream(downapkfile); byte[] buf = new byte[1024];//分配byte conn.connect(); double count = 0; if (conn.getResponseCode() >= 400) { } else { while (count <= 100) { if (is != null) { int numRead = is.read(buf); if (numRead <= 0) { sendMessage(1,0); break; } else { // 设置进度 fileOutput.write(buf, 0, numRead); loadedlength += numRead; int mprogress = (int) ((loadedlength*100)/contentlength);// 设置下载进度,更新// 设置通知发送消息给NOtifyManager进行更新(进度更新,状态更新),判断状态 System.out.println("ppp" + mprogress); if(oldprocess <= mprogress-2 ){// 避免notifymanager ANR,每下载百分之2才进行通知一次 oldprocess =mprogress; sendMessage(0, mprogress); } } } else { break; } } } conn.disconnect();//记得关闭连接 fileOutput.close(); is.close(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } catch (KeyManagementException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
0 0
- 屏蔽HTTPS证书验证下载apk安装包
- android+https网址屏蔽证书+IntentService+NotifyManager通知栏+下载apk文件+在通知栏显示下载进度+完成之后提示安装
- 访问webview屏蔽https证书
- Https验证证书
- Https 证书验证问题
- https之证书验证
- 安装APK,提示“该安装包未包含任何证书”
- IOS安装包分发(windows+tomcat+私有证书https)
- Fiddler Https 抓包 CertEnroll engine 无法安装证书
- Xposed绕过SSL 抓https包,不用安装证书
- charles ios https证书安装后不能抓包 unknown
- APP中https证书有效性验证引发安全问题(例Fiddler可抓https包)
- APP中https证书有效性验证引发安全问题(例Fiddler可抓https包)
- apache安装https证书
- jdk安装https证书
- tomcat安装Https证书
- OKHttp HTTPS 请求证书验证 PEM证书
- https 证书验证 okhttp https设置
- 改造间隙扯淡1:机器人产品
- ViewPager的动画效果
- 阅读一百本计算机著作吧,少年
- Android性能调优利器StrictMode
- netmap分析(1)
- 屏蔽HTTPS证书验证下载apk安装包
- PHP ORM框架与简单代码实现—让OOP与关系数据库更融洽
- 设计模式--桥接模式
- CentOS7—Apache—多个虚拟站点—semodule
- ExpandableListView
- 【程序人生】:关于招聘的一个理解
- Building apps for Firefox OS
- iOS获取路由器地址
- Welcome to Swagger-PHP’s documentation!