如何自定义CA证书

package com.example.customssl;import android.content.Context;
import org.apache.http.client.HttpClient;
import org.apache.http.conn.scheme.PlainSocketFactory;
import org.apache.http.conn.scheme.Scheme;
import org.apache.http.conn.scheme.SchemeRegistry;
import org.apache.http.conn.ssl.AllowAllHostnameVerifier;
import org.apache.http.conn.ssl.SSLSocketFactory;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpParams;import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManagerFactory;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.cert.Certificate;
import java.security.cert.CertificateException;
import java.security.cert.CertificateFactory;public class CustomCAHttpsProvider {/*** Creates a {@link org.apache.http.client.HttpClient} which is configured to work with a custom authority* certificate.** @param context       Application Context* @param certRawResId  R.raw.id of certificate file (*.crt). Should be stored in /res/raw.* @param allowAllHosts If true then client will not check server against host names of certificate.* @return Http Client.* @throws Exception If there is an error initializing the client.*/public static HttpClient getHttpClient(Context context, int certRawResId, boolean allowAllHosts) throws Exception {// build key store with ca certificateKeyStore keyStore = buildKeyStore(context, certRawResId);// init ssl socket factory with key storeSSLSocketFactory sslSocketFactory = new SSLSocketFactory(keyStore);// skip hostname security check if specifiedif (allowAllHosts) {sslSocketFactory.setHostnameVerifier(new AllowAllHostnameVerifier());}// basic http params for clientHttpParams params = new BasicHttpParams();// normal scheme registry with our ssl socket factory for "https"SchemeRegistry schemeRegistry = new SchemeRegistry();schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));schemeRegistry.register(new Scheme("https", sslSocketFactory, 443));// create connection managerThreadSafeClientConnManager cm = new ThreadSafeClientConnManager(params, schemeRegistry);// create http clientreturn new DefaultHttpClient(cm, params);}/*** Creates a {@link javax.net.ssl.HttpsURLConnection} which is configured to work with a custom authority* certificate.** @param urlString     remote url string.* @param context       Application Context* @param certRawResId  R.raw.id of certificate file (*.crt). Should be stored in /res/raw.* @param allowAllHosts If true then client will not check server against host names of certificate.* @return Http url connection.* @throws Exception If there is an error initializing the connection.*/public static HttpsURLConnection getHttpsUrlConnection(String urlString, Context context, int certRawResId,boolean allowAllHosts) throws Exception {// build key store with ca certificateKeyStore keyStore = buildKeyStore(context, certRawResId);// Create a TrustManager that trusts the CAs in our KeyStoreString tmfAlgorithm = TrustManagerFactory.getDefaultAlgorithm();TrustManagerFactory tmf = TrustManagerFactory.getInstance(tmfAlgorithm);tmf.init(keyStore);// Create an SSLContext that uses our TrustManagerSSLContext sslContext = SSLContext.getInstance("TLS");sslContext.init(null, tmf.getTrustManagers(), null);// Create a connection from urlURL url = new URL(urlString);HttpsURLConnection urlConnection = (HttpsURLConnection) url.openConnection();urlConnection.setSSLSocketFactory(sslContext.getSocketFactory());// skip hostname security check if specifiedif (allowAllHosts) {urlConnection.setHostnameVerifier(new AllowAllHostnameVerifier());}return urlConnection;}private static KeyStore buildKeyStore(Context context, int certRawResId) throws KeyStoreException, CertificateException, NoSuchAlgorithmException, IOException {// init a default key storeString keyStoreType = KeyStore.getDefaultType();KeyStore keyStore = KeyStore.getInstance(keyStoreType);keyStore.load(null, null);// read and add certificate authorityCertificate cert = readCert(context, certRawResId);keyStore.setCertificateEntry("ca", cert);return keyStore;}private static Certificate readCert(Context context, int certResourceId) throws CertificateException, IOException {// read certificate resourceInputStream caInput = context.getResources().openRawResource(certResourceId);Certificate ca;try {// generate a certificateCertificateFactory cf = CertificateFactory.getInstance("X.509");ca = cf.generateCertificate(caInput);} finally {caInput.close();}return ca;}}

Frida 拦截

Java.perform(function () {const CertificateFactory = Java.use('java.security.cert.CertificateFactory')const certList = [];CertificateFactory.getInstance.overload('java.lang.String').implementation=function (type) {certList[Thread.currentThread().getId()]=typereturn this.getInstance(type)}
CertificateFactory.generateCertificate.overload('java.io.InputStream').implementation=function (input) {var type= certList[Thread.currentThread().getId()]console.log("type:",type)console.log("hex:\n",input)console.log("hex:\n",tool.Hexdump(tool.FridaTool().readBin(input)))return this.generateCertificate(input)}});

参考

  • https://stackoverflow.com/a/23697732/12457105

Android逆向之CA证书提取相关推荐

  1. Android——自建CA证书,实现https请求

    Android 使用https 协议请求客户端 server端操作 自己创建 CA 证书 拿自建CA 证书创建 server 端证书 创建 https 服务 Android客户端操作 创建项目并引入相 ...

  2. eap wifi 证书_如何以编程方式在Android中安装CA证书(用于EAP WiFi配置)?

    我的目标:在Android programmitcally中创建一个EAP WiFi配置 - 包括CA证书 . 问题:如何以编程方式安装CA证书(然后在EAP WiFi配置中引用该证书)? 但是,假设 ...

  3. eap方法 华为手机怎么连wifi_如何以编程方式在Android中安装CA证书(用于EAP WiFi配置)?...

    我的目标: 在 Android programmitcally中创建EAP WiFi配置 – 包括CA证书. 问题: 如何以编程方式安装CA证书(然后在EAP WiFi配置中引用该证书)? 但是,这假 ...

  4. 【Android 逆向】APK 文件格式 ( Android 应用安装 | Zip 文件格式 | 使用 Python 代码提取 APK 文件 )

    文章目录 一.Android 应用安装 二.APK 文件格式 三.使用 Python 提取 APK 文件 一.Android 应用安装 APK 是 Android 应用的安装文件 , 现在也有 AAB ...

  5. 【SSL】openssl 提取 PKCS 证书库中的公钥、私钥、证书、密钥、CA证书

    前言 openssl 1.1.1g 证书库格式 PKCS12 测试证书库 test.pfx .该证书库仅有一套证书(多套证书公用一个证书库的情况未测试). 查看证书库 openssl pkcs12 - ...

  6. android系统证书导入工具,如何将CA证书导入Android手机?

    我想使用Nexus One连接到大学的无线网络.当我转到"无线设置"中的"添加Wi-Fi网络"时,我填写网络SSID并选择802.1x Enterprise作为 ...

  7. Android https 自签名和CA证书验证(基于OkHttp)

    Android HTTPS自签名和CA证书验证(基于OkHttp) HTTPS介绍 CA证书 自签名证书 问题描述 域名校验 OkHttp设置 总结 HTTPS介绍 HTTPS是一种通过计算机网络进行 ...

  8. OpenSSL生成CA自签名根证书和颁发证书和证书提取

    CA根证书 生成流程 第一步 生成CA证书私钥 1.#生成ca私钥 (.key 和 pem 只是格式不一样) openssl genrsa -aes128 -passout pass:Test@202 ...

  9. 教你如何将CA证书导入Android手机

    第一:Android只能理解CA的二进制格式,只能使用文件格式* .crt. 第二:Android只能理解* .p12文件格式的用户证书. 因此,您可以检查您的CA文件二进制文件或文本是否非常简单:使 ...

最新文章

  1. 取IDE当前文档所在项目的目录[vs.net2008]
  2. Power BI商业智能与业务分析的结合,让你在企业中脱颖而出
  3. js判断是安卓手机还是ios
  4. 使用SAP Spartacus的route给标准页面维护alias入口
  5. MySQL内核调试_内核调试技巧
  6. 怎么看作业部落的html,HTML问题汇总
  7. Json格式字符串转换成Json格式数据
  8. FIR 带通滤波器参数设计流程
  9. 蓝桥杯单片机数码管技巧
  10. SpringCloud_03_Feign入门示例
  11. html和js制作个人所得税表格,用JS编写个人所得税计算器
  12. python bytes类型中是ascii码_Python3 中bytes数据类型深入理解(ASCII码对照表)
  13. 使用多种AI算法玩方格迷宫——基于Value的RL算法 【开源】
  14. 一、线性表的顺序存储和基本运算
  15. 展示正在活动时间内的活动,过期活动不显示
  16. Revit中栏杆扶手、坡道的绘制及插件太多问题
  17. 20135203齐岳 信息安全系统设计基础期末总结
  18. Rosalind第11题——ros_bio11_FIBD
  19. 如何注册小程序账号和下载小程序开发工具
  20. Vue 项目安装 scss 以及报错的解决方法 --- Window10 系统 和 Mac OS 系统

热门文章

  1. 【Python爬虫】下载b站视频。超详细。
  2. 计算机开机硬盘扫描,win7系统开机自动扫描硬盘的原因及解决方法
  3. cb4cle计数器如何设计九分频电路
  4. ECharts大屏数据可视化展示
  5. 【Qt开发笔记】Qt设置生成的exe文件图标
  6. 最新 eCharts 世界地图国家名映射
  7. vs用html制作表格,演练:在 Visual Web Developer 中编辑 HTML 表格
  8. r语言实现关联分析--关联规则挖掘(Apriori算法) (r语言预测学习笔记)
  9. 辽宁 viewpro.php,辽宁省策划学会赴沙地沟村考察
  10. 拖拽式生成CMS和在线商店:Microweber