Package java.security.cert

Examples of java.security.cert.TrustAnchor


            Set hashSet = new HashSet();
            String[] aliases = getTrustCertificates();
            for (int i = 0; i < aliases.length; i++) {
                Certificate cert = getCertificate(aliases[i]);
                if (cert instanceof X509Certificate) {
                    hashSet.add(new TrustAnchor((X509Certificate) cert, null));
                }
            }
            PKIXParameters param = new PKIXParameters(hashSet);
            // Do not check a revocation list
            param.setRevocationEnabled(false);
View Full Code Here


                // which isn't useful at all
                Set<TrustAnchor> anchors = new HashSet<TrustAnchor>(); // CertificateUtil.getDefaultRootCAs();
                Jenkins j = Jenkins.getInstance();
                for (String cert : (Set<String>) j.servletContext.getResourcePaths("/WEB-INF/update-center-rootCAs")) {
                    if (cert.endsWith(".txt"))  continue;       // skip text files that are meant to be documentation
                    anchors.add(new TrustAnchor((X509Certificate)cf.generateCertificate(j.servletContext.getResourceAsStream(cert)),null));
                }
                File[] cas = new File(j.root, "update-center-rootCAs").listFiles();
                if (cas!=null) {
                    for (File cert : cas) {
                        if (cert.getName().endsWith(".txt"))  continue;       // skip text files that are meant to be documentation
                        FileInputStream in = new FileInputStream(cert);
                        try {
                            anchors.add(new TrustAnchor((X509Certificate)cf.generateCertificate(in),null));
                        } finally {
                            in.close();
                        }
                    }
                }
View Full Code Here

                while (truststoreAliases.hasMoreElements()) {
                    String alias = truststoreAliases.nextElement();
                    X509Certificate cert =
                        (X509Certificate) truststore.getCertificate(alias);
                    if (cert != null) {
                        TrustAnchor anchor =
                            new TrustAnchor(cert, cert.getExtensionValue(NAME_CONSTRAINTS_OID));
                        set.add(anchor);
                    }
                }
            }

            //
            // Add certificates from the keystore - only if there is no TrustStore, apart from
            // the case that the truststore is the JDK CA certs. This behaviour is preserved
            // for backwards compatibility reasons
            //
            if (keystore != null && (truststore == null || loadCACerts)) {
                Enumeration<String> aliases = keystore.aliases();
                while (aliases.hasMoreElements()) {
                    String alias = aliases.nextElement();
                    X509Certificate cert =
                        (X509Certificate) keystore.getCertificate(alias);
                    if (cert != null) {
                        TrustAnchor anchor =
                            new TrustAnchor(cert, cert.getExtensionValue(NAME_CONSTRAINTS_OID));
                        set.add(anchor);
                    }
                }
            }
View Full Code Here

        GeneralSecurityException
    {
        // Create a set of trust anchors using the root certificates.
        HashSet<TrustAnchor> anchors = new HashSet<TrustAnchor>();
        for (X509Certificate rootCertificate : rootCertificates) {
            anchors.add(new TrustAnchor(rootCertificate, null));
        }

        // Prepare to build a certificate path.
        X509CertSelector selector = new X509CertSelector();
        selector.setCertificate(certificate);
View Full Code Here

     *
     * @param cert the certificate which serves as the trust anchor
     * @return the newly constructed TrustAnchor
     */
    protected TrustAnchor buildTrustAnchor(X509Certificate cert) {
        return new TrustAnchor(cert, null);
    }
View Full Code Here

        log.debug("Target certificate: {}", x500DNHandler.getName(targetCert.getSubjectX500Principal()));
        for (Certificate cert : buildResult.getCertPath().getCertificates()) {
            log.debug("CertPath certificate: {}", x500DNHandler.getName(((X509Certificate) cert)
                    .getSubjectX500Principal()));
        }
        TrustAnchor ta = buildResult.getTrustAnchor();
        if (ta.getTrustedCert() != null) {
            log.debug("TrustAnchor: {}", x500DNHandler.getName(ta.getTrustedCert().getSubjectX500Principal()));
        } else if (ta.getCA() != null) {
            log.debug("TrustAnchor: {}", x500DNHandler.getName(ta.getCA()));
        } else {
            log.debug("TrustAnchor: {}", ta.getCAName());
        }
    }
View Full Code Here

    }

    private Set<TrustAnchor> asTrustAnchors(List<X509Certificate> trustedAuthorityCerts) {
        Set<TrustAnchor> trustAnchors = new HashSet<TrustAnchor>();
        for (X509Certificate trustedAuthorityCert : trustedAuthorityCerts) {
            trustAnchors.add(new TrustAnchor(trustedAuthorityCert, null));
        }
        return trustAnchors;
    }
View Full Code Here

            certchain.addAll(cACertChain);
            certchain.add(verCert);
            CertPath cp = CertificateFactory.getInstance("X.509","BC").generateCertPath(certchain);

            Set<TrustAnchor> trust = new HashSet<TrustAnchor>();
            trust.add(new TrustAnchor(rootCert, null));

            CertPathValidator cpv = CertPathValidator.getInstance("PKIX","BC");
            PKIXParameters param = new PKIXParameters(trust);
            param.addCertStore(store);
            param.setDate(new Date());                 
View Full Code Here

            throw new CertPathValidatorException("CVC certificate chain can not be of length longer than two.");
          }
        } else {
          // Normal X509 certificates
          HashSet<TrustAnchor> trustancors = new HashSet<TrustAnchor>();
          TrustAnchor trustanchor = null;
          trustanchor = new TrustAnchor((X509Certificate)rootcert, null);
          trustancors.add(trustanchor);

          // Create the parameters for the validator
          PKIXParameters params = new PKIXParameters(trustancors);

          // Disable CRL checking since we are not supplying any CRLs
          params.setRevocationEnabled(false);
          params.setDate( new Date() );

          // Create the validator and validate the path
          CertPathValidator certPathValidator = CertPathValidator.getInstance(CertPathValidator.getDefaultType(), "BC");
          CertificateFactory fact = CertTools.getCertificateFactory();
          CertPath certpath = fact.generateCertPath(calist);

          CertPathValidatorResult result = certPathValidator.validate(certpath, params);

          // Get the certificates validate in the path
          PKIXCertPathValidatorResult pkixResult = (PKIXCertPathValidatorResult)result;
          returnval.addAll(certpath.getCertificates());

          // Get the CA used to validate this path
          TrustAnchor ta = pkixResult.getTrustAnchor();
          X509Certificate cert = ta.getTrustedCert();
          returnval.add(cert);
        }
      }
      return returnval;
    } // createCertChain
View Full Code Here

        final Set<TrustAnchor> anchors
                = new HashSet<TrustAnchor>();
        for (Certificate cert : trustedCerts) {
          if (cert instanceof X509Certificate) {
                anchors.add(new TrustAnchor((X509Certificate)cert, null));
      }
        }

        final CertPathBuilder cpb = CertPathBuilder.getInstance("PKIX");
        X509CertSelector targetConstraints = new X509CertSelector();
View Full Code Here

TOP

Related Classes of java.security.cert.TrustAnchor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.