当前位置: 首页>>代码示例>>Java>>正文


Java PKIXCertPathBuilderResult.getCertPath方法代码示例

本文整理汇总了Java中java.security.cert.PKIXCertPathBuilderResult.getCertPath方法的典型用法代码示例。如果您正苦于以下问题:Java PKIXCertPathBuilderResult.getCertPath方法的具体用法?Java PKIXCertPathBuilderResult.getCertPath怎么用?Java PKIXCertPathBuilderResult.getCertPath使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.security.cert.PKIXCertPathBuilderResult的用法示例。


在下文中一共展示了PKIXCertPathBuilderResult.getCertPath方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import java.security.cert.PKIXCertPathBuilderResult; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
    // reset the security property to make sure that the algorithms
    // and keys used in this test are not disabled.
    Security.setProperty("jdk.certpath.disabledAlgorithms", "MD2");

    X509Certificate rootCert = CertUtils.getCertFromFile("anchor.cer");
    TrustAnchor anchor = new TrustAnchor
        (rootCert.getSubjectX500Principal(), rootCert.getPublicKey(), null);
    X509CertSelector sel = new X509CertSelector();
    sel.setBasicConstraints(-2);
    PKIXBuilderParameters params = new PKIXBuilderParameters
        (Collections.singleton(anchor), sel);
    params.setRevocationEnabled(false);
    X509Certificate eeCert = CertUtils.getCertFromFile("ee.cer");
    X509Certificate caCert = CertUtils.getCertFromFile("ca.cer");
    ArrayList<X509Certificate> certs = new ArrayList<X509Certificate>();
    certs.add(caCert);
    certs.add(eeCert);
    CollectionCertStoreParameters ccsp =
        new CollectionCertStoreParameters(certs);
    CertStore cs = CertStore.getInstance("Collection", ccsp);
    params.addCertStore(cs);
    PKIXCertPathBuilderResult res = CertUtils.build(params);
    CertPath cp = res.getCertPath();
    // check that first certificate is an EE cert
    List<? extends Certificate> certList = cp.getCertificates();
    X509Certificate cert = (X509Certificate) certList.get(0);
    if (cert.getBasicConstraints() != -1) {
        throw new Exception("Target certificate is not an EE certificate");
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:32,代码来源:BuildEEBasicConstraints.java

示例2: main

import java.security.cert.PKIXCertPathBuilderResult; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {

        X509Certificate rootCert = CertUtils.getCertFromFile("anchor.cer");
        TrustAnchor anchor = new TrustAnchor
            (rootCert.getSubjectX500Principal(), rootCert.getPublicKey(), null);
        X509CertSelector sel = new X509CertSelector();
        sel.setBasicConstraints(-2);
        PKIXBuilderParameters params = new PKIXBuilderParameters
            (Collections.singleton(anchor), sel);
        params.setRevocationEnabled(false);
        X509Certificate eeCert = CertUtils.getCertFromFile("ee.cer");
        X509Certificate caCert = CertUtils.getCertFromFile("ca.cer");
        ArrayList<X509Certificate> certs = new ArrayList<X509Certificate>();
        certs.add(caCert);
        certs.add(eeCert);
        CollectionCertStoreParameters ccsp =
            new CollectionCertStoreParameters(certs);
        CertStore cs = CertStore.getInstance("Collection", ccsp);
        params.addCertStore(cs);
        PKIXCertPathBuilderResult res = CertUtils.build(params);
        CertPath cp = res.getCertPath();
        // check that first certificate is an EE cert
        List<? extends Certificate> certList = cp.getCertificates();
        X509Certificate cert = (X509Certificate) certList.get(0);
        if (cert.getBasicConstraints() != -1) {
            throw new Exception("Target certificate is not an EE certificate");
        }
    }
 
开发者ID:openjdk,项目名称:jdk7-jdk,代码行数:29,代码来源:BuildEEBasicConstraints.java

示例3: baseTest

import java.security.cert.PKIXCertPathBuilderResult; //导入方法依赖的package包/类
private void baseTest()
    throws Exception
{
    CertificateFactory cf = CertificateFactory.getInstance("X.509", "BC");

        // initialise CertStore
    X509Certificate rootCert = (X509Certificate)cf.generateCertificate(new ByteArrayInputStream(CertPathTest.rootCertBin));
    X509Certificate interCert = (X509Certificate)cf.generateCertificate(new ByteArrayInputStream(CertPathTest.interCertBin));
    X509Certificate finalCert = (X509Certificate)cf.generateCertificate(new ByteArrayInputStream(CertPathTest.finalCertBin));
    X509CRL rootCrl = (X509CRL)cf.generateCRL(new ByteArrayInputStream(CertPathTest.rootCrlBin));
    X509CRL interCrl = (X509CRL)cf.generateCRL(new ByteArrayInputStream(CertPathTest.interCrlBin));
    List list = new ArrayList();
    list.add(rootCert);
    list.add(interCert);
    list.add(finalCert);
    list.add(rootCrl);
    list.add(interCrl);
    CollectionCertStoreParameters ccsp = new CollectionCertStoreParameters(list);
    CertStore store = CertStore.getInstance("Collection", ccsp, "BC");
    Calendar validDate = Calendar.getInstance();
    validDate.set(2008,8,4,14,49,10);

        //Searching for rootCert by subjectDN without CRL
    Set trust = new HashSet();
    trust.add(new TrustAnchor(rootCert, null));

    CertPathBuilder cpb = CertPathBuilder.getInstance("PKIX","BC");
    X509CertSelector targetConstraints = new X509CertSelector();
    targetConstraints.setSubject(finalCert.getSubjectX500Principal().getEncoded());
    PKIXBuilderParameters params = new PKIXBuilderParameters(trust, targetConstraints);
    params.addCertStore(store);
    params.setDate(validDate.getTime());
    PKIXCertPathBuilderResult result = (PKIXCertPathBuilderResult) cpb.build(params);
    CertPath                  path = result.getCertPath();

    if (path.getCertificates().size() != 2)
    {
        fail("wrong number of certs in baseTest path");
    }
}
 
开发者ID:NoYouShutup,项目名称:CryptMeme,代码行数:41,代码来源:CertPathBuilderTest.java

示例4: v0Test

import java.security.cert.PKIXCertPathBuilderResult; //导入方法依赖的package包/类
private void v0Test()
    throws Exception
{
    // create certificates and CRLs
    KeyPair         rootPair = TestUtils.generateRSAKeyPair();
    KeyPair         interPair = TestUtils.generateRSAKeyPair();
    KeyPair         endPair = TestUtils.generateRSAKeyPair();

    X509Certificate rootCert = TestUtils.generateRootCert(rootPair);
    X509Certificate interCert = TestUtils.generateIntermediateCert(interPair.getPublic(), rootPair.getPrivate(), rootCert);
    X509Certificate endCert = TestUtils.generateEndEntityCert(endPair.getPublic(), interPair.getPrivate(), interCert);

    BigInteger      revokedSerialNumber = BigInteger.valueOf(2);
    X509CRL         rootCRL = TestUtils.createCRL(rootCert, rootPair.getPrivate(), revokedSerialNumber);
    X509CRL         interCRL = TestUtils.createCRL(interCert, interPair.getPrivate(), revokedSerialNumber);

    // create CertStore to support path building
    List list = new ArrayList();

    list.add(rootCert);
    list.add(interCert);
    list.add(endCert);
    list.add(rootCRL);
    list.add(interCRL);

    CollectionCertStoreParameters params = new CollectionCertStoreParameters(list);
    CertStore                     store = CertStore.getInstance("Collection", params);

    // build the path
    CertPathBuilder  builder = CertPathBuilder.getInstance("PKIX", "BC");
    X509CertSelector pathConstraints = new X509CertSelector();

    pathConstraints.setSubject(endCert.getSubjectX500Principal().getEncoded());

    PKIXBuilderParameters buildParams = new PKIXBuilderParameters(Collections.singleton(new TrustAnchor(rootCert, null)), pathConstraints);

    buildParams.addCertStore(store);
    buildParams.setDate(new Date());

    PKIXCertPathBuilderResult result = (PKIXCertPathBuilderResult)builder.build(buildParams);
    CertPath                  path = result.getCertPath();

    if (path.getCertificates().size() != 2)
    {
        fail("wrong number of certs in v0Test path");
    }
}
 
开发者ID:NoYouShutup,项目名称:CryptMeme,代码行数:48,代码来源:CertPathBuilderTest.java


注:本文中的java.security.cert.PKIXCertPathBuilderResult.getCertPath方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。