當前位置: 首頁>>代碼示例>>Java>>正文


Java X509Certificate.getIssuerDN方法代碼示例

本文整理匯總了Java中java.security.cert.X509Certificate.getIssuerDN方法的典型用法代碼示例。如果您正苦於以下問題:Java X509Certificate.getIssuerDN方法的具體用法?Java X509Certificate.getIssuerDN怎麽用?Java X509Certificate.getIssuerDN使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.security.cert.X509Certificate的用法示例。


在下文中一共展示了X509Certificate.getIssuerDN方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getCertificateChain

import java.security.cert.X509Certificate; //導入方法依賴的package包/類
public static List<X509Certificate> getCertificateChain(
        List<X509Certificate> certs, X509Certificate leaf) {
    List<X509Certificate> unusedCerts = new ArrayList<>(certs);
    List<X509Certificate> result = new ArrayList<>(1);
    result.add(leaf);
    unusedCerts.remove(leaf);
    X509Certificate root = leaf;
    while (!root.getSubjectDN().equals(root.getIssuerDN())) {
        Principal targetDn = root.getIssuerDN();
        boolean issuerFound = false;
        for (int i = 0; i < unusedCerts.size(); i++) {
            X509Certificate unusedCert = unusedCerts.get(i);
            if (targetDn.equals(unusedCert.getSubjectDN())) {
                issuerFound = true;
                unusedCerts.remove(i);
                result.add(unusedCert);
                root = unusedCert;
                break;
            }
        }
        if (!issuerFound) {
            break;
        }
    }
    return result;
}
 
開發者ID:F8LEFT,項目名稱:FApkSigner,代碼行數:27,代碼來源:V1SchemeVerifier.java

示例2: buildChain

import java.security.cert.X509Certificate; //導入方法依賴的package包/類
/**
 * Recursively tries to establish chain from pool of trusted certs.
 *
 * @param certToVerify the cert that needs to be verified.
 * @param chain the chain that's being built.
 * @param certs the pool of trusted certs
 *
 * @return true if successful, false otherwise.
 */
private boolean buildChain(X509Certificate certToVerify,
                    Vector<Certificate> chain,
                    Hashtable<Principal, Vector<Certificate>> certs) {
    Principal issuer = certToVerify.getIssuerDN();
    if (isSelfSigned(certToVerify)) {
        // reached self-signed root cert;
        // no verification needed because it's trusted.
        chain.addElement(certToVerify);
        return true;
    }

    // Get the issuer's certificate(s)
    Vector<Certificate> vec = certs.get(issuer);
    if (vec == null) {
        return false;
    }

    // Try out each certificate in the vector, until we find one
    // whose public key verifies the signature of the certificate
    // in question.
    for (Enumeration<Certificate> issuerCerts = vec.elements();
         issuerCerts.hasMoreElements(); ) {
        X509Certificate issuerCert
            = (X509Certificate)issuerCerts.nextElement();
        PublicKey issuerPubKey = issuerCert.getPublicKey();
        try {
            certToVerify.verify(issuerPubKey);
        } catch (Exception e) {
            continue;
        }
        if (buildChain(issuerCert, chain, certs)) {
            chain.addElement(certToVerify);
            return true;
        }
    }
    return false;
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:47,代碼來源:Main.java

示例3: populateCertIssuerNames

import java.security.cert.X509Certificate; //導入方法依賴的package包/類
/**
 * Populate array of Issuer DNs from certificates and convert
 * each Principal to type X500Name if necessary.
 */
private void populateCertIssuerNames() {
    if (certificates == null)
        return;

    certIssuerNames = new Principal[certificates.length];
    for (int i = 0; i < certificates.length; i++) {
        X509Certificate cert = certificates[i];
        Principal certIssuerName = cert.getIssuerDN();
        if (!(certIssuerName instanceof X500Name)) {
            // must extract the original encoded form of DN for
            // subsequent name comparison checks (converting to a
            // String and back to an encoded DN could cause the
            // types of String attribute values to be changed)
            try {
                X509CertInfo tbsCert =
                    new X509CertInfo(cert.getTBSCertificate());
                certIssuerName = (Principal)
                    tbsCert.get(X509CertInfo.ISSUER + "." +
                                X509CertInfo.DN_NAME);
            } catch (Exception e) {
                // error generating X500Name object from the cert's
                // issuer DN, leave name as is.
            }
        }
        certIssuerNames[i] = certIssuerName;
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:32,代碼來源:PKCS7.java

示例4: getCertificateChain

import java.security.cert.X509Certificate; //導入方法依賴的package包/類
public ArrayList<X509Certificate> getCertificateChain(PKCS7 block)
    throws IOException
{
    X509Certificate userCert;
    userCert = block.getCertificate(certificateSerialNumber, issuerName);
    if (userCert == null)
        return null;

    ArrayList<X509Certificate> certList = new ArrayList<X509Certificate>();
    certList.add(userCert);

    X509Certificate[] pkcsCerts = block.getCertificates();
    if (pkcsCerts == null
        || userCert.getSubjectDN().equals(userCert.getIssuerDN())) {
        return certList;
    }

    Principal issuer = userCert.getIssuerDN();
    int start = 0;
    while (true) {
        boolean match = false;
        int i = start;
        while (i < pkcsCerts.length) {
            if (issuer.equals(pkcsCerts[i].getSubjectDN())) {
                // next cert in chain found
                certList.add(pkcsCerts[i]);
                // if selected cert is self-signed, we're done
                // constructing the chain
                if (pkcsCerts[i].getSubjectDN().equals(
                                        pkcsCerts[i].getIssuerDN())) {
                    start = pkcsCerts.length;
                } else {
                    issuer = pkcsCerts[i].getIssuerDN();
                    X509Certificate tmpCert = pkcsCerts[start];
                    pkcsCerts[start] = pkcsCerts[i];
                    pkcsCerts[i] = tmpCert;
                    start++;
                }
                match = true;
                break;
            } else {
                i++;
            }
        }
        if (!match)
            break;
    }

    return certList;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:51,代碼來源:SignerInfo.java

示例5: getCertificateChain

import java.security.cert.X509Certificate; //導入方法依賴的package包/類
public ArrayList<X509Certificate> getCertificateChain(PKCS7 block)
    throws IOException
{
    X509Certificate userCert;
    userCert = block.getCertificate(certificateSerialNumber, issuerName);
    if (userCert == null)
        return null;

    ArrayList<X509Certificate> certList = new ArrayList<>();
    certList.add(userCert);

    X509Certificate[] pkcsCerts = block.getCertificates();
    if (pkcsCerts == null
        || userCert.getSubjectDN().equals(userCert.getIssuerDN())) {
        return certList;
    }

    Principal issuer = userCert.getIssuerDN();
    int start = 0;
    while (true) {
        boolean match = false;
        int i = start;
        while (i < pkcsCerts.length) {
            if (issuer.equals(pkcsCerts[i].getSubjectDN())) {
                // next cert in chain found
                certList.add(pkcsCerts[i]);
                // if selected cert is self-signed, we're done
                // constructing the chain
                if (pkcsCerts[i].getSubjectDN().equals(
                                        pkcsCerts[i].getIssuerDN())) {
                    start = pkcsCerts.length;
                } else {
                    issuer = pkcsCerts[i].getIssuerDN();
                    X509Certificate tmpCert = pkcsCerts[start];
                    pkcsCerts[start] = pkcsCerts[i];
                    pkcsCerts[i] = tmpCert;
                    start++;
                }
                match = true;
                break;
            } else {
                i++;
            }
        }
        if (!match)
            break;
    }

    return certList;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:51,代碼來源:SignerInfo.java


注:本文中的java.security.cert.X509Certificate.getIssuerDN方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。