Android 4.4系统HTTPS证书校验

charles&fiddler安卓手机安装系统级ca证书抓取https请求信息 文章目录问题描述问题分析解决问题思路开始1、从charles端导出ca证书2、windows系统安装openssl3、使用openssl工具计算hash值总结 问题描述 使用charles或fiddler对手机进行app抓包时,对于https请求不能正确的截取请求信息,通过观察抓包软件仅能看到TLS管道建立或大量请求失败的记录。 问题分析 charles或fiddler缺少正确、完整的ca证书,因此不能与client建立TLS连接。 charles或fiddler安装在手机端的ca证书会被作为用户层面的信 阅读详情

Android系统在建立HTTPS三次握手后会进行证书校验,接下来根据android 4.4系统代码来看一下证书校验流程

 

从org.conscrypt.TrustManagerImpl开始介绍

1、证书校验入口函数 

 @Override 
public void checkServerTrusted(X509Certificate[] chain, String authType)
            throws CertificateException {
        checkTrusted(chain, authType, null, false);
}

2、下一个调用函数

private List<X509Certificate> checkTrusted(X509Certificate[] chain, String authType,
                                               String host, boolean clientAuth)
            throws CertificateException {
        if (chain == null || chain.length == 0 || authType == null || authType.length() == 0) {
            throw new IllegalArgumentException("null or zero-length parameter");
        }
        if (err != null) {
            throw new CertificateException(err);
        }
 
        // get the cleaned up chain and trust anchor
        Set<TrustAnchor> trustAnchor = new HashSet<TrustAnchor>(); // there can only be one!
        X509Certificate[] newChain = cleanupCertChainAndFindTrustAnchors(chain, trustAnchor);
 
        // add the first trust anchor to the chain, which may be an intermediate
        List<X509Certificate> wholeChain = new ArrayList<X509Certificate>();
        wholeChain.addAll(Arrays.asList(newChain));
        // trustAnchor is actually just a single element
        for (TrustAnchor trust : trustAnchor) {
            wholeChain.add(trust.getTrustedCert());
        }
 
        // add all the cached certificates from the cert index, avoiding loops
        // this gives us a full chain from leaf to root, which we use for cert pinning and pass
        // back out to callers when we return.
        X509Certificate last = wholeChain.get(wholeChain.size() - 1);
        while (true) {
            TrustAnchor cachedTrust = trustedCertificateIndex.findByIssuerAndSignature(last);
            // the cachedTrust can be null if there isn't anything in the index or if a user has
            // trusted a non-self-signed cert.
            if (cachedTrust == null) {
                break;
            }
 
            // at this point we have a cached trust anchor, but don't know if its one we got from
            // the server. Extract the cert, compare it to the last element in the chain, and add it
            // if we haven't seen it before.
            X509Certificate next = cachedTrust.getTrustedCert();
            if (next != last) {
                wholeChain.add(next);
                last = next;
            } else {
                // if next == last then we found a self-signed cert and the chain is done
                break;
            }
        }
 
        // build the cert path from the array of certs sans trust anchors
        CertPath certPath = factory.generateCertPath(Arrays.asList(newChain));
 
        if (host != null) {
            boolean chainIsNotPinned = true;
            try {
                chainIsNotPinned = pinManager.chainIsNotPinned(host, wholeChain);
            } catch (PinManagerException e) {
                throw new CertificateException(e);
            }
            if (chainIsNotPinned) {
                throw new CertificateException(new CertPathValidatorException(
                        "Certificate path is not properly pinned.", null, certPath, -1));
            }
        }
 
        if (newChain.length == 0) {
            // chain was entirely trusted, skip the validator
            return wholeChain;
        }
 
        if (trustAnchor.isEmpty()) {
            throw new CertificateException(new CertPathValidatorException(
                    "Trust anchor for certification path not found.", null, certPath, -1));
        }
 
        // There's no point in checking trust anchors here, and it will throw off the MD5 check,
        // so we just hand it the chain without anchors
        ChainStrengthAnalyzer.check(newChain);
 
        try {
            PKIXParameters params = new PKIXParameters(trustAnchor);
            params.setRevocationEnabled(false);
            params.addCertPathChecker(new ExtendedKeyUsagePKIXCertPathChecker(clientAuth,
                                                                              newChain[0]));
            validator.validate(certPath, params);
            // Add intermediate CAs to the index to tolerate sites
            // that assume that the browser will have cached these.
            // The server certificate is skipped by skipping the
            // zeroth element of new chain and note that the root CA
            // will have been removed in
            // cleanupCertChainAndFindTrustAnchors.  http://b/3404902
            for (int i = 1; i < newChain.length; i++) {
                trustedCertificateIndex.index(newChain[i]);
            }
        } catch (InvalidAlgorithmParameterException e) {
            throw new CertificateException(e);
        } catch (CertPathValidatorException e) {
            throw new CertificateException(e);
        }
 
        return wholeChain;
}

这个函数里面主要内容是:

1、整理证书链,调用函数是cleanupCertChainAndFindTrustAnchors:

private X509Certificate[] cleanupCertChainAndFindTrustAnchors(X509Certificate[] chain,
                                                                  Set<TrustAnchor> trustAnchors) {
        X509Certificate[] original = chain;
 
        // 1. Clean the received certificates chain.
        int currIndex;
        // Start with the first certificate in the chain, assuming it
        // is the leaf certificate (server or client cert).
        for (currIndex = 0; currIndex < chain.length; currIndex++) {
            // Walk the chain to find a "subject" matching
            // the "issuer" of the current certificate. In a properly
            // ordered chain this should be the next cert and be fast.
            // If not, we reorder things to be as the validator will
            // expect.
            boolean foundNext = false;
            for (int nextIndex = currIndex + 1; nextIndex < chain.length; nextIndex++) {
                if (chain[currIndex].getIssuerDN().equals(chain[nextIndex].getSubjectDN())) {
                    foundNext = true;
                    // Exchange certificates so that 0 through currIndex + 1 are in proper order
                    if (nextIndex != currIndex + 1) {
                        // don't mutuate original chain, which may be directly from an SSLSession
                        if (chain == original) {
                            chain = original.clone();
                        }
                        X509Certificate tempCertificate = chain[nextIndex];
                        chain[nextIndex] = chain[currIndex + 1];
                        chain[currIndex + 1] = tempCertificate;
                    }
                    break;
                }
            }
            // If we can't find the next in the chain, just give up
            // and use what we found so far. This drops unrelated
            // certificates that have nothing to do with the cert
            // chain.
            if (!foundNext) {
                break;
            }
        }
 
        // 2. Find the trust anchor in the chain, if any
        int anchorIndex;
        for (anchorIndex = 0; anchorIndex <= currIndex; anchorIndex++) {
            // If the current cert is a TrustAnchor, we can ignore the rest of the chain.
            // This avoids including "bridge" CA certs that added for legacy compatibility.
            TrustAnchor trustAnchor = findTrustAnchorBySubjectAndPublicKey(chain[anchorIndex]);
            if (trustAnchor != null) {
                trustAnchors.add(trustAnchor);
                break;
            }
        }
 
        // 3. If the chain is now shorter, copy to an appropriately sized array.
        int chainLength = anchorIndex;
        X509Certificate[] newChain = ((chainLength == chain.length)
                                      ? chain
                                      : Arrays.copyOf(chain, chainLength));
 
        // 4. If we didn't find a trust anchor earlier, look for one now
        if (trustAnchors.isEmpty()) {
            TrustAnchor trustAnchor = findTrustAnchorByIssuerAndSignature(newChain[anchorIndex-1]);
            if (trustAnchor != null) {
                trustAnchors.add(trustAnchor);
            }
        }
        return newChain;
 }

该函数主要功能是将传进来的证书链的证书按subject和issuer确立父子关系,调整好顺序,删除不相关的证书,然后从证书链第一个证书开始寻找系统中与它subject和public key相同的证书作为信任证书,如果找到的话就会返回新的证书链,这个证书链根证书就是第一个找到系统对应证书的那个证书

备注:如果证书链中只有一个证书,那么只会校验该证书的subject和public key是否和系统中的某一个证书一样,并不会像校验证书链那样用public key去校验证书签名,之所以这样,我的理解是因为https是公钥加密私钥解密的非对称加密,所以私钥不一样公钥肯定也不一样,所以即使你把公钥改成和系统证书一样,那你拿到数据后你没有对应的私钥也解不出来,所以只要校验公钥是否一样就足够了。

 

2、整理好证书链以及获取到系统的一个证书后开始进行校验,校验函数是validator.validate(certPath, params);先来看一下validator这个变量哪来的

public TrustManagerImpl(KeyStore keyStore, CertPinManager manager) {
        CertPathValidator validatorLocal = null;
        CertificateFactory factoryLocal = null;
        KeyStore rootKeyStoreLocal = null;
        TrustedCertificateStore trustedCertificateStoreLocal = null;
        TrustedCertificateIndex trustedCertificateIndexLocal = null;
        X509Certificate[] acceptedIssuersLocal = null;
        Exception errLocal = null;
        try {
            validatorLocal = CertPathValidator.getInstance("PKIX");
            factoryLocal = CertificateFactory.getInstance("X509");
 
            // if we have an AndroidCAStore, we will lazily load CAs
            if ("AndroidCAStore".equals(keyStore.getType())) {
                rootKeyStoreLocal = keyStore;
                trustedCertificateStoreLocal = new TrustedCertificateStore();
                acceptedIssuersLocal = null;
                trustedCertificateIndexLocal = new TrustedCertificateIndex();
            } else {
                rootKeyStoreLocal = null;
                trustedCertificateStoreLocal = null;
                acceptedIssuersLocal = acceptedIssuers(keyStore);
                trustedCertificateIndexLocal
                        = new TrustedCertificateIndex(trustAnchors(acceptedIssuersLocal));
            }
 
        } catch (Exception e) {
            errLocal = e;
        }
 
        if (manager != null) {
            this.pinManager = manager;
        } else {
            try {
                pinManager = new CertPinManager(trustedCertificateStoreLocal);
            } catch (PinManagerException e) {
                throw new SecurityException("Could not initialize CertPinManager", e);
            }
        }
 
        this.rootKeyStore = rootKeyStoreLocal;
        this.trustedCertificateStore = trustedCertificateStoreLocal;
        this.validator = validatorLocal;
        this.factory = factoryLocal;
        this.trustedCertificateIndex = trustedCertificateIndexLocal;
        this.acceptedIssuers = acceptedIssuersLocal;
        this.err = errLocal;
}

可以看到这个变量是通过validatorLocal = CertPathValidator.getInstance("PKIX");创建的,返回的实例是security provider中的一个对象,具体路径是

org.bouncycastle.jce.provider.PKIXCertPathBuilderSpi,校验是调用validate函数,这个函数定义在类java.security.cert.CertPathValidator里:

public final CertPathValidatorResult validate(CertPath certPath,
            CertPathParameters params) throws CertPathValidatorException,
            InvalidAlgorithmParameterException {
        return spiImpl.engineValidate(certPath, params);
}
可以看到它调用了它的实现类里面的engineValidate方法,这个实现类就是上面说的

PKIXCertPathBuilderSpi,接着我们来看一下这个函数具体内容: 

public CertPathValidatorResult engineValidate(
            CertPath certPath,
            CertPathParameters params)
            throws CertPathValidatorException,
            InvalidAlgorithmParameterException
    {
        if (!(params instanceof PKIXParameters))
        {
            throw new InvalidAlgorithmParameterException("Parameters must be a " + PKIXParameters.class.getName()
                    + " instance.");
        }
 
        ExtendedPKIXParameters paramsPKIX;
        if (params instanceof ExtendedPKIXParameters)
        {
            paramsPKIX = (ExtendedPKIXParameters)params;
        }
        else
        {
            paramsPKIX = ExtendedPKIXParameters.getInstance((PKIXParameters)params);
        }
        if (paramsPKIX.getTrustAnchors() == null)
        {
            throw new InvalidAlgorithmParameterException(
                    "trustAnchors is null, this is not allowed for certification path validation.");
        }
 
        //
        // 6.1.1 - inputs
        //
 
        //
        // (a)
        //
        List certs = certPath.getCertificates();
        int n = certs.size();
 
        if (certs.isEmpty())
        {
            throw new CertPathValidatorException("Certification path is empty.", null, certPath, 0);
        }
        // BEGIN android-added
        {
            X509Certificate cert = (X509Certificate) certs.get(0);
 
            if (cert != null) {
                BigInteger serial = cert.getSerialNumber();
                if (blacklist.isSerialNumberBlackListed(serial)) {
                    // emulate CRL exception message in RFC3280CertPathUtilities.checkCRLs
                    String message = "Certificate revocation of serial 0x" + serial.toString(16);
                    System.out.println(message);
                    AnnotatedException e = new AnnotatedException(message);
                    throw new CertPathValidatorException(e.getMessage(), e, certPath, 0);
                }
            }
        }
        // END android-added
 
        //
        // (b)
        //
        // Date validDate = CertPathValidatorUtilities.getValidDate(paramsPKIX);
 
        //
        // (c)
        //
        Set userInitialPolicySet = paramsPKIX.getInitialPolicies();
 
        //
        // (d)
        //
        TrustAnchor trust;
        try
        {
            trust = CertPathValidatorUtilities.findTrustAnchor((X509Certificate) certs.get(certs.size() - 1),
                    paramsPKIX.getTrustAnchors(), paramsPKIX.getSigProvider());
        }
        catch (AnnotatedException e)
        {
            throw new CertPathValidatorException(e.getMessage(), e, certPath, certs.size() - 1);
        }
 
        if (trust == null)
        {
            throw new CertPathValidatorException("Trust anchor for certification path not found.", null, certPath, -1);
        }
 
        //
        // (e), (f), (g) are part of the paramsPKIX object.
        //
        Iterator certIter;
        int index = 0;
        int i;
        // Certificate for each interation of the validation loop
        // Signature information for each iteration of the validation loop
        //
        // 6.1.2 - setup
        //
 
        //
        // (a)
        //
        List[] policyNodes = new ArrayList[n + 1];
        for (int j = 0; j < policyNodes.length; j++)
        {
            policyNodes[j] = new ArrayList();
        }
 
        Set policySet = new HashSet();
 
        policySet.add(RFC3280CertPathUtilities.ANY_POLICY);
 
        PKIXPolicyNode validPolicyTree = new PKIXPolicyNode(new ArrayList(), 0, policySet, null, new HashSet(),
                RFC3280CertPathUtilities.ANY_POLICY, false);
 
        policyNodes[0].add(validPolicyTree);
 
        //
        // (b) and (c)
        //
        PKIXNameConstraintValidator nameConstraintValidator = new PKIXNameConstraintValidator();
 
        // (d)
        //
        int explicitPolicy;
        Set acceptablePolicies = new HashSet();
 
        if (paramsPKIX.isExplicitPolicyRequired())
        {
            explicitPolicy = 0;
        }
        else
        {
            explicitPolicy = n + 1;
        }
 
        //
        // (e)
        //
        int inhibitAnyPolicy;
 
        if (paramsPKIX.isAnyPolicyInhibited())
        {
            inhibitAnyPolicy = 0;
        }
        else
        {
            inhibitAnyPolicy = n + 1;
        }
 
        //
        // (f)
        //
        int policyMapping;
 
        if (paramsPKIX.isPolicyMappingInhibited())
        {
            policyMapping = 0;
        }
        else
        {
            policyMapping = n + 1;
        }
 
        //
        // (g), (h), (i), (j)
        //
        PublicKey workingPublicKey;
        X500Principal workingIssuerName;
 
        X509Certificate sign = trust.getTrustedCert();
        try
        {
            if (sign != null)
            {
                workingIssuerName = CertPathValidatorUtilities.getSubjectPrincipal(sign);
                workingPublicKey = sign.getPublicKey();
            }
            else
            {
                workingIssuerName = new X500Principal(trust.getCAName());
                workingPublicKey = trust.getCAPublicKey();
            }
        }
        catch (IllegalArgumentException ex)
        {
            throw new ExtCertPathValidatorException("Subject of trust anchor could not be (re)encoded.", ex, certPath,
                    -1);
        }
 
        AlgorithmIdentifier workingAlgId = null;
        try
        {
            workingAlgId = CertPathValidatorUtilities.getAlgorithmIdentifier(workingPublicKey);
        }
        catch (CertPathValidatorException e)
        {
            throw new ExtCertPathValidatorException(
                    "Algorithm identifier of public key of trust anchor could not be read.", e, certPath, -1);
        }
        DERObjectIdentifier workingPublicKeyAlgorithm = workingAlgId.getObjectId();
        ASN1Encodable workingPublicKeyParameters = workingAlgId.getParameters();
 
        //
        // (k)
        //
        int maxPathLength = n;
 
        //
        // 6.1.3
        //
 
        if (paramsPKIX.getTargetConstraints() != null
                && !paramsPKIX.getTargetConstraints().match((X509Certificate) certs.get(0)))
        {
            throw new ExtCertPathValidatorException(
                    "Target certificate in certification path does not match targetConstraints.", null, certPath, 0);
        }
 
        //
        // initialize CertPathChecker's
        //
        List pathCheckers = paramsPKIX.getCertPathCheckers();
        certIter = pathCheckers.iterator();
        while (certIter.hasNext())
        {
            ((PKIXCertPathChecker) certIter.next()).init(false);
        }
 
        X509Certificate cert = null;
 
        for (index = certs.size() - 1; index >= 0; index--)
        {
            // BEGIN android-added
            if (blacklist.isPublicKeyBlackListed(workingPublicKey)) {
                // emulate CRL exception message in RFC3280CertPathUtilities.checkCRLs
                String message = "Certificate revocation of public key " + workingPublicKey;
                System.out.println(message);
                AnnotatedException e = new AnnotatedException(message);
                throw new CertPathValidatorException(e.getMessage(), e, certPath, index);
            }
            // END android-added
            // try
            // {
            //
            // i as defined in the algorithm description
            //
            i = n - index;
 
            //
            // set certificate to be checked in this round
            // sign and workingPublicKey and workingIssuerName are set
            // at the end of the for loop and initialized the
            // first time from the TrustAnchor
            //
            cert = (X509Certificate) certs.get(index);
            boolean verificationAlreadyPerformed = (index == certs.size() - 1);
 
            //
            // 6.1.3
            //
 
            RFC3280CertPathUtilities.processCertA(certPath, paramsPKIX, index, workingPublicKey,
                verificationAlreadyPerformed, workingIssuerName, sign);
 
            RFC3280CertPathUtilities.processCertBC(certPath, index, nameConstraintValidator);
 
            validPolicyTree = RFC3280CertPathUtilities.processCertD(certPath, index, acceptablePolicies,
                    validPolicyTree, policyNodes, inhibitAnyPolicy);
 
            validPolicyTree = RFC3280CertPathUtilities.processCertE(certPath, index, validPolicyTree);
 
            RFC3280CertPathUtilities.processCertF(certPath, index, validPolicyTree, explicitPolicy);
 
            //
            // 6.1.4
            //
 
            if (i != n)
            {
                if (cert != null && cert.getVersion() == 1)
                {
                    throw new CertPathValidatorException("Version 1 certificates can't be used as CA ones.", null,
                            certPath, index);
                }
 
                RFC3280CertPathUtilities.prepareNextCertA(certPath, index);
 
                validPolicyTree = RFC3280CertPathUtilities.prepareCertB(certPath, index, policyNodes, validPolicyTree,
                        policyMapping);
 
                RFC3280CertPathUtilities.prepareNextCertG(certPath, index, nameConstraintValidator);
 
                // (h)
                explicitPolicy = RFC3280CertPathUtilities.prepareNextCertH1(certPath, index, explicitPolicy);
                policyMapping = RFC3280CertPathUtilities.prepareNextCertH2(certPath, index, policyMapping);
                inhibitAnyPolicy = RFC3280CertPathUtilities.prepareNextCertH3(certPath, index, inhibitAnyPolicy);
 
                //
                // (i)
                //
                explicitPolicy = RFC3280CertPathUtilities.prepareNextCertI1(certPath, index, explicitPolicy);
                policyMapping = RFC3280CertPathUtilities.prepareNextCertI2(certPath, index, policyMapping);
 
                // (j)
                inhibitAnyPolicy = RFC3280CertPathUtilities.prepareNextCertJ(certPath, index, inhibitAnyPolicy);
 
                // (k)
                RFC3280CertPathUtilities.prepareNextCertK(certPath, index);
 
                // (l)
                maxPathLength = RFC3280CertPathUtilities.prepareNextCertL(certPath, index, maxPathLength);
 
                // (m)
                maxPathLength = RFC3280CertPathUtilities.prepareNextCertM(certPath, index, maxPathLength);
 
                // (n)
                RFC3280CertPathUtilities.prepareNextCertN(certPath, index);
 
                Set criticalExtensions = cert.getCriticalExtensionOIDs();
                if (criticalExtensions != null)
                {
                    criticalExtensions = new HashSet(criticalExtensions);
 
                    // these extensions are handled by the algorithm
                    criticalExtensions.remove(RFC3280CertPathUtilities.KEY_USAGE);
                    criticalExtensions.remove(RFC3280CertPathUtilities.CERTIFICATE_POLICIES);
                    criticalExtensions.remove(RFC3280CertPathUtilities.POLICY_MAPPINGS);
                    criticalExtensions.remove(RFC3280CertPathUtilities.INHIBIT_ANY_POLICY);
                    criticalExtensions.remove(RFC3280CertPathUtilities.ISSUING_DISTRIBUTION_POINT);
                    criticalExtensions.remove(RFC3280CertPathUtilities.DELTA_CRL_INDICATOR);
                    criticalExtensions.remove(RFC3280CertPathUtilities.POLICY_CONSTRAINTS);
                    criticalExtensions.remove(RFC3280CertPathUtilities.BASIC_CONSTRAINTS);
                    criticalExtensions.remove(RFC3280CertPathUtilities.SUBJECT_ALTERNATIVE_NAME);
                    criticalExtensions.remove(RFC3280CertPathUtilities.NAME_CONSTRAINTS);
                }
                else
                {
                    criticalExtensions = new HashSet();
                }
 
                // (o)
                RFC3280CertPathUtilities.prepareNextCertO(certPath, index, criticalExtensions, pathCheckers);
                
                // set signing certificate for next round
                sign = cert;
 
                // (c)
                workingIssuerName = CertPathValidatorUtilities.getSubjectPrincipal(sign);
 
                // (d)
                try
                {
                    workingPublicKey = CertPathValidatorUtilities.getNextWorkingKey(certPath.getCertificates(), index);
                }
                catch (CertPathValidatorException e)
                {
                    throw new CertPathValidatorException("Next working key could not be retrieved.", e, certPath, index);
                }
 
                workingAlgId = CertPathValidatorUtilities.getAlgorithmIdentifier(workingPublicKey);
                // (f)
                workingPublicKeyAlgorithm = workingAlgId.getObjectId();
                // (e)
                workingPublicKeyParameters = workingAlgId.getParameters();
            }
        }
 
        ...

这个函数内容比较多,主要截取前面部分,大概流程是

1、找到我们之前整理证书链时找到的那个对应的系统证书

2、用找到的系统证书的public key校验证书链根证书,方法如下:

 protected static void verifyX509Certificate(X509Certificate cert, PublicKey publicKey,
                                                String sigProvider)
        throws GeneralSecurityException
    {
        if (sigProvider == null)
        {
            cert.verify(publicKey);
        }
        else
        {
            cert.verify(publicKey, sigProvider);
        }
}

3、开始校验证书链,其中校验签名的函数是processCertA:

protected static void processCertA(
        CertPath certPath,
        ExtendedPKIXParameters paramsPKIX,
        int index,
        PublicKey workingPublicKey,
        boolean verificationAlreadyPerformed,
        X500Principal workingIssuerName,
        X509Certificate sign)
        throws ExtCertPathValidatorException
    {
        List certs = certPath.getCertificates();
        X509Certificate cert = (X509Certificate)certs.get(index);
        //
        // (a) verify
        //
        if (!verificationAlreadyPerformed)
        {
            try
            {
                // (a) (1)
                //
                CertPathValidatorUtilities.verifyX509Certificate(cert, workingPublicKey,
                    paramsPKIX.getSigProvider());
            }
            catch (GeneralSecurityException e)
            {
                throw new ExtCertPathValidatorException("Could not validate certificate signature.", e, certPath, index);
            }
        }
 
        try
        {
            // (a) (2)
            //
            cert.checkValidity(CertPathValidatorUtilities
                .getValidCertDateFromValidityModel(paramsPKIX, certPath, index));
        }
        catch (CertificateExpiredException e)
        {
            throw new ExtCertPathValidatorException("Could not validate certificate: " + e.getMessage(), e, certPath, index);
        }
        catch (CertificateNotYetValidException e)
        {
            throw new ExtCertPathValidatorException("Could not validate certificate: " + e.getMessage(), e, certPath, index);
        }
        catch (AnnotatedException e)
        {
            throw new ExtCertPathValidatorException("Could not validate time of certificate.", e, certPath, index);
        }
 
        //
        // (a) (3)
        //
        if (paramsPKIX.isRevocationEnabled())
        {
            try
            {
                checkCRLs(paramsPKIX, cert, CertPathValidatorUtilities.getValidCertDateFromValidityModel(paramsPKIX,
                    certPath, index), sign, workingPublicKey, certs);
            }
            catch (AnnotatedException e)
            {
                Throwable cause = e;
                if (null != e.getCause())
                {
                    cause = e.getCause();
                }
                throw new ExtCertPathValidatorException(e.getMessage(), cause, certPath, index);
            }
        }
 
        //
        // (a) (4) name chaining
        //
        if (!CertPathValidatorUtilities.getEncodedIssuerPrincipal(cert).equals(workingIssuerName))
        {
            throw new ExtCertPathValidatorException("IssuerName(" + CertPathValidatorUtilities.getEncodedIssuerPrincipal(cert)
                + ") does not match SubjectName(" + workingIssuerName + ") of signing certificate.", null,
                certPath, index);
        }
}

这个函数同样是用public key校验签名以及校验证书的有效性

 

4、按照3中的方法从证书链的根证书的下一个证书开始每次拿上一个证书的public key校验下一个证书,直到证书链最底端的证书,任何一步校验错误都会认为证书不合法

5、除了校验签名以外,还有很多校验,具体可以查看

org.bouncycastle.jce.provider.RFC3280CertPathUtilities这个类




HTTPS 原理浅析及其在 Android 中的使用 作者:曹丰斌   本文首先分析HTTP协议在安全性上的不足,进而阐述HTTPS实现安全通信的关键技术点和原理。然后通过抓包分析HTTPS协议的握手以及通信过程。最后总结一下自己在开发过程中遇到的HTTPS相关的问题,并给出当前项目中对HTTPS问题的系统解决方案,以供总结和分享。如有不当之处,欢迎批评和指正。1.HTTP协议的不足  HTTP1.x在传输数据时,所有传输的内容都是明文,客户端和服务器 阅读详情

相关推荐

解决android4.4以下sslv3 alert handshake failure和protocol TLSv1.3 is not supported的问题

解决android4.4以下sslv3 alert handshake failure和protocol TLSv1.3 is not supported的问题

kuanxu的专栏 2375

Https在4.4以下手机上不好用问题,用okhttp进行设置可以解决

经过很多测试,httpclient,httpsUrlconnection 设置ssl工厂都没看到作用,有部分文章说4.4以下手机默认不支持https,用okhttp之后进行如下这是可以起作用,附件为工厂类 public synchronized  OkHttpClient getClient(){                  if (okHttpClient == null) {

lgwy855的博客 977

安卓证书安装为系统证书(模拟器版)

背景/遇到的问题:(HTTPS第三方窗口无法抓包) 因项目要求,原HTTP链接换成了加密链接HTTPS;导致安卓手机的第三方浏览器/原生嵌套窗口Webveiw无法正常抓包HTTPS的内容; 问题分析:(请教了大佬) 使用的环境:WINDOWS10、EMUI 11、Charles 4.5.6、APP 排查问题的思路是先从能读到证书的方法来验证; 1、在电脑浏览器请求对应的HTTPS链接,查看抓包工具能否正常抓到;如果不能,电脑端证书就有问题,重装下再试试; 2、电脑端正常的情况下,在手机上自带浏览器里请求对

iiill的博客 8357

使用OkHttp请求https在android4.4报错javax.net.ssl.SSLHandshakeException: javax.net.ssl.SSLProtocolException

对于HTTPS的请求我们一般都是采取忽略的策略,一般而言直接实现X509TrustManager接口,简单的以SSLContext获取SSLSocketFactory就可以的了,实测6.0以上还未遇到过什么奇葩的问题,6.0以下的,正常情况下也不会有什么问题,但最近偶然发现一客户提供的https地址请求居然报错了,抛出了javax.net.ssl.SSLHandshakeExcep...

q1581375053的博客 3250

Android 7.0以上版本将Charles证书转换并添加到Android系统证书,方便HTTPS抓包

Android 7.0以上版本将Charles证书转换并添加到Android系统证书,方便HTTPS抓包

m0_59683157的博客 9546

安卓Root下系统证书目录配置:HTTPS抓包最后一公里

安卓HTTPS抓包失效,本质是App对证书的信任机制问题——自Android 7.0起,targetSdkVersion≥24的应用默认仅信任/system/etc/security/cacerts/下的系统级CA证书,而非用户安装的证书。其原理基于OpenSSL的subject_hash_old哈希命名规则、DER二进制编码强制要求及root:root+644刚性权限控制。该机制保障了应用层SSL校验的安全性,但也成为调试与安全测试的关键瓶颈。典型应用场景包括金融类App抓包分析、网络协议逆向、自动化渗透

weixin_30363509的博客 674

Android 4.4 HTTPS通信问题与OKHTTP解决方案

HTTPS作为现代网络通信的安全基石,其核心机制TLS协议在不同Android版本上存在兼容性差异。以TLS 1.2为例,该协议通过加密套件协商和证书验证机制保障传输安全,但在Android 4.4等旧版本系统中,开发者常会遇到协议支持不完整和设备时间校验等问题。通过分析OKHTTP框架的ConnectionSpec配置和X509TrustManager实现原理,可以定制TLS版本和加密套件组合,同时结合NTP时间同步策略解决证书验证失败问题。这些技术方案特别适用于需要兼容老旧Android设备的企业级应用

weixin_30162121的博客 60

如何将抓包工具证书(cer,crt, pem)写入到Android系统内置根证书目录中实现 HTTPS 抓包

如何让抓包工具证书(cer,crt, pem)写入到Android系统内置根证书中,实现 HTTPS 抓包

Specif1c的博客 8488

安卓 https 证书校验和绕过

吕元江。

AzulSystems的博客 3168

安卓高版本HTTPS抓包实战:从证书信任链到系统证书安装

HTTPS协议通过SSL/TLS证书信任链确保通信安全,其核心原理是客户端验证服务器证书是否由受信任的根证书颁发机构签发。在移动应用开发和安全测试领域,为了分析网络流量、调试接口或进行安全评估,常需对HTTPS流量进行解密,这便引入了中间人攻击的技术场景。抓包工具通过扮演中间人角色,拦截并解密流量,其技术价值在于为开发调试、安全审计和性能分析提供了关键可见性。然而,自Android 7.0起,系统默认只信任预置的系统证书,不再信任用户安装的证书,这直接导致常规抓包方法失效。本文聚焦于解决这一核心挑战,详细阐

aiman5818的博客 425

Android APP之WebView如何校验SSL证书

请参考以下代码,原理是:如果webview报告SSL错误,程序将会对服务器证书进行强校验,如果服务器传入证书的指纹(sha256)与记录值一致,说明webview验证过程存在缺陷(如:手机日期错误、根证书被删除 等),忽略SSL错误;SSL错误的处理方式十分关键,如果处理不当,可能导致中间人攻击,黑客窃听数据,进而引发安全事故。如果APP需要访问多张证书,请在代码中加入多个证书指纹数值。在测试代码时,请将手机日期设置在证书有效期之前,判断WebView是否能正常访问HTTPS站点。

欢迎来到鸾姝淡月博客,专为程序员和编程爱好者打造的技术博客。我们分享编程语言趋势、开发工具、编程哲学、职业发展等,助你掌握新技术,优化技能,激发编程热情。 1172

Android https证书校验、防抓包

android https证书校验,防抓包

conerconced的博客 2500

Steam游戏上架全流程:从Steamworks注册到SteamPipe构建发布

在数字游戏分发领域,Steam是开发者绕不开的核心平台。其背后的Steamworks开发者后台不仅承担账号认证、税务表单与商店页搭建,更通过一套名为SteamPipe的构建上传系统,将游戏包体以Depot仓库的形式同步给全球玩家。理解这套机制,本质上就是理解游戏从本地工程到云端分发的完整链路:开发者在本地配置构建脚本,通过steamcmd上传Build,再在后台设置默认分支和Beta分支,最终完成审核与价格策略的制定。这一流程不仅关乎技术操作,也直接影响愿望单转化率、新品曝光与玩家社区运营。无论是独立开发者

weixin_32288959的博客 372

安卓模拟器内app抓包 导入证书到安卓系统证书

安卓模拟器抓包准备抓包软件1.burp2.fiddler下载地址fiddler代理配置安卓模拟器安装模拟器安装过程模拟器代理配置查看主机ip模拟器设置模拟器安装证书到系统下面准备条件adb配置pem证书准备操作步骤 准备抓包软件 下面介绍两种抓包软件,fiddler配置较为简单 1.burp burp配置参考另一篇文章参考 最后从浏览器导出证书 PortSwigger CA.cer 证书格式为 cer,我这里重命名为 burp.cer,方便后面导入到安卓模拟器 2.fiddler 下载地址

qq_29176323的博客 1万+

Stata实战:RCS限制立方样条非线性关系建模与P值解读全攻略

本文详细介绍了在Stata中使用RCS限制立方样条进行非线性关系建模的全过程,包括数据准备、节点设置、COX回归模型构建、结果可视化及P值解读。通过乳腺癌临床数据实例,展示了如何捕捉年龄与死亡风险之间的复杂非线性关系,并提供了实用的Stata代码和图形优化技巧。

weixin_30650039的博客 480

STM32+OV7670实战:5步搞定低成本人脸识别门禁系统(附完整代码)

本文详细介绍了基于STM32单片机和OV7670摄像头构建低成本离线人脸识别门禁系统的完整实战方案。文章从硬件选型、电路设计避坑入手,逐步讲解了图像采集优化、轻量级人脸检测与LBP特征提取策略,并提供了离线人脸库管理、特征比对以及系统集成的具体实现方法,附有核心代码示例,旨在帮助开发者快速实现可落地的嵌入式视觉应用。

kubernetes8ctl的博客 579

android 导入系统证书,安卓手机添加系统证书方法(HTTPS抓包)

安卓7.0以后,安卓不信任用户安装的证书,所以抓https时无法解码请求,对于第三方应用,需要将证书添加为系统证书,网上解决方法较多,比如使用安卓模拟器(兼容性差,很多应用闪退),使用xposed框架等,这里使用安卓手机添加证书。注:需要手机有root权限,以下操作以小米9 SE为准,其他品牌手机操作可能有差别。1. 导出证书(以Charles为例)help --> SSL Proxyin...

weixin_31702225的博客 1万+

如何在 R 中使用 Gamma 分布(附示例)

在统计学中,伽马分布通常用于模拟与等待时间相关的概率。我们可以使用以下函数来处理 R 中的 gamma 分布:dgamma(x, shape, rate) – 找到具有特定形状和速率参数的 gamma 分布的密度函数值。 pgamma(q, shape, rate) – 找到具有特定形状和速率参数的伽马分布的累积密度函数值。 qgamma(p, shape, rate) – 找到具有特定形状和速率参数的 gamma 分布的逆累积密度函数值。 rgamma(n, shape, rate) – 生成 n 个随机

Mrrunsen的博客 4425

【APK安全】HTTPS证书校验的核心风险与防御指南

在移动应用通信中,HTTPS 通过 “证书校验 + 加密传输” 构建信任体系,但 APK 若存在证书校验缺陷(如忽略 CA 验证、放行过期证书),会导致中间人攻击(MITM)有机可乘 —— 攻击者可伪造证书拦截请求、篡改返回数据(如修改支付金额、窃取登录 Token)。Android 15(API 35)进一步强化 HTTPS 安全管控(如禁用 TLS 1.0/1.1、强制证书透明性),本文聚焦五大核心校验要点,拆解风险场景、提供适配方案,筑牢 APK 通信安全防线。

水滴石穿 1035

YOLO26 改进 - 注意力机制 | Mask Attention掩码注意力,可学习掩码矩阵破解低分辨率特征提取难题 | 2025 预印

本文提出了用于低分辨率图像分割的MaskAttn - UNet框架,并将其核心的掩码注意力机制集成到YOLO26中。传统U - Net类模型难以捕捉全局关联,Transformer类模型计算量大,而掩码注意力机制通过可学习的掩码,让模型选择性关注重要区域,融合了卷积的局部效率和注意力的全局视野。其工作流程包括特征适配、掩码生成、定向注意力计算和特征融合。我们将掩码注意力机制代码集成到YOLO26中。

魔改工程师的博客 844

【NVIDIA-GB200-1】国内第一份生产环境实战安装配置教程,配置安装脚本,nvidia gb200配置教程-复制即用;gb200驱动安装

GB200 的高性能通信依赖。

jundao1997的专栏 723

安卓HTTPS证书校验原理与绕过技术详解

HTTPS作为互联网通信的基础安全协议,通过TLS/SSL实现数据加密和身份认证。其核心机制依赖证书链验证,包括检查CA签名、有效期和域名匹配等环节。在安卓开发中,系统默认会执行严格的证书校验流程,而高级安全实践如公钥固定(Pinning)能进一步防范中间人攻击。但随着安卓版本迭代,从7.0开始引入网络安全配置限制,开发者需要适配不同系统的证书处理差异。实际工程中常需处理代理调试、APK反编译修改和Frida动态Hook等证书绕过场景,特别是金融类APP常采用多层防御策略。理解这些证书校验机制对移动安全测试

weixin_30851867的博客 344

基于STM32、HAL库的TLV320AIC3204IRHBR音频接口芯片驱动程序设计

* 开启所有数字部分 */#define TLV320AIC3204_REG_LEFT_HEADPHONE_OUT_VOLUME 0x0C /* 左声道耳机输出音量 */#define TLV320AIC3204_REG_DIGITAL_AUDIO_PATH_CONTROL 0x05 /* 数字音频路径控制 */#define TLV320AIC3204_REG_ANALOG_HP_FILTER_CONTROL 0x34 /* 模拟耳机滤波器控制 *//* 最大音量 */

corlin6688的博客 529

android webview 添加证书,Android webview手动校验https证书(by 星空武哥)

有些时候由于Android系统的bug或者其他的原因,导致我们的webview不能验证通过我们的https证书,最明显的例子就是华为手机mate7升级到Android7.0后,手机有些网站打不开了,而更新了webview的补丁后就没问题了,充分说明系统的bug对我们混合开发webview加载https地址的影响是巨大的。那么我们怎么去解决这个问题呢?首先我们去分析一下出现的原因当webview加载...

weixin_32143245的博客 1574

深度探索:VS2022 牵手 DeepSeek,开启开发新征程

通过将 VS2022 与 DeepSeek 接入,我们成功开启了智能开发的新征程。从前期的硬件准备、软件环境搭建,到实战环节的一步步配置与整合,再到全面的测试与验证,每一个步骤都充满挑战,但也带来了满满的收获。在实际应用中,VS2022 与 DeepSeek 的结合展现出了强大的优势,为开发者带来了更高的效率和更出色的代码质量。无论是代码自动补全、智能代码审查,还是自然语言交互编程,都让开发过程变得更加智能、便捷,极大地提升了开发体验。

远程部署调试 运行安装 项目调试 二次开发 项目技术新 持续迭代 部分源码免费分享 3538

廖雪峰Python教程[完整版]

廖雪峰的python教程整理的,已经排好版了,而且还是完整的,适合小白

手机抓https包安卓7以上ca证书安装方法

可以到设置中查看是否有对应的证书, 不同手机位置可能不同miui9开发版: 系统设置 → 更多设置 → 系统安全 → 加密与凭证 → 信任的凭据雷电模拟器(Android9): 设置 → 安全性和位置信息 → 加密与凭证 → 信任的凭据。

专注自动化、性能测试、测试架构学习交流 2779

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

上一篇: Android View事件传播机制
下一篇: Android 7.0系统校验证书流程
梦翼-
博客等级 码龄13年 22粉丝 45原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值