Package java.security.cert

Examples of java.security.cert.CertificateFactory


    }


    private static X509Certificate generateCertificate( byte[] data ) throws Exception
    {
        CertificateFactory cf = CertificateFactory.getInstance( "X.509" ); //$NON-NLS-1$
        Certificate certificate = cf.generateCertificate( new ByteArrayInputStream( data ) );
        if ( certificate instanceof X509Certificate )
        {
            return ( X509Certificate ) certificate;
        }
View Full Code Here


                    new ByteArrayInputStream(certData.getBytes(),
                            certData.getStart(),
                            certData.getLength());
                // Fill the  elements.
                try {
                    CertificateFactory cf;
                    if (clientCertProvider == null) {
                        cf = CertificateFactory.getInstance("X.509");
                    } else {
                        cf = CertificateFactory.getInstance("X.509",
                                clientCertProvider);
                    }
                    while(bais.available() > 0) {
                        X509Certificate cert = (X509Certificate)
                        cf.generateCertificate(bais);
                        if(jsseCerts == null) {
                            jsseCerts = new X509Certificate[1];
                            jsseCerts[0] = cert;
                        } else {
                            X509Certificate [] temp = new X509Certificate[jsseCerts.length+1];
View Full Code Here

                    System.getProperty(Constants.CATALINA_BASE_PROP), crlf);
        }
        Collection<? extends CRL> crls = null;
        InputStream is = null;
        try {
            CertificateFactory cf = CertificateFactory.getInstance("X.509");
            is = new FileInputStream(crlFile);
            crls = cf.generateCRLs(is);
        } catch(IOException iex) {
            throw iex;
        } catch(CRLException crle) {
            throw crle;
        } catch(CertificateException ce) {
View Full Code Here

                    X509Certificate[] certs = null;
                    if (certLength > 0) {
                        certs = new X509Certificate[certLength];
                        for (int i = 0; i < certLength; i++) {
                            byte[] data = SSLSocket.getInfoB(socket, SSL.SSL_INFO_CLIENT_CERT_CHAIN + i);
                            CertificateFactory cf =
                                CertificateFactory.getInstance("X.509");
                            ByteArrayInputStream stream = new ByteArrayInputStream(data);
                            certs[i] = (X509Certificate) cf.generateCertificate(stream);
                        }
                    }
                    if (certs != null) {
                        request.setAttribute
                            (AprEndpoint.CERTIFICATE_KEY, certs);
                    }
                    // User key size
                    sslO = new Integer(SSLSocket.getInfoI(socket, SSL.SSL_INFO_CIPHER_USEKEYSIZE));
                    if (sslO != null) {
                        request.setAttribute
                            (AprEndpoint.KEY_SIZE_KEY, sslO);
                    }
                    // SSL session ID
                    sslO = SSLSocket.getInfoS(socket, SSL.SSL_INFO_SESSION_ID);
                    if (sslO != null) {
                        request.setAttribute
                            (AprEndpoint.SESSION_ID_KEY, sslO);
                    }
                } catch (Exception e) {
                    log.warn(sm.getString("http11processor.socket.ssl"), e);
                }
            }

        } else if (actionCode == ActionCode.ACTION_REQ_SSL_CERTIFICATE) {

            if (ssl && (socket != 0)) {
                 // Consume and buffer the request body, so that it does not
                 // interfere with the client's handshake messages
                InputFilter[] inputFilters = inputBuffer.getFilters();
                ((BufferedInputFilter) inputFilters[Constants.BUFFERED_FILTER])
                    .setLimit(maxSavePostSize);
                inputBuffer.addActiveFilter
                    (inputFilters[Constants.BUFFERED_FILTER]);
                try {
                    // Renegociate certificates
                    SSLSocket.renegotiate(socket);
                    // Client certificate chain if present
                    int certLength = SSLSocket.getInfoI(socket, SSL.SSL_INFO_CLIENT_CERT_CHAIN);
                    X509Certificate[] certs = null;
                    if (certLength > 0) {
                        certs = new X509Certificate[certLength];
                        for (int i = 0; i < certLength; i++) {
                            byte[] data = SSLSocket.getInfoB(socket, SSL.SSL_INFO_CLIENT_CERT_CHAIN + i);
                            CertificateFactory cf =
                                CertificateFactory.getInstance("X.509");
                            ByteArrayInputStream stream = new ByteArrayInputStream(data);
                            certs[i] = (X509Certificate) cf.generateCertificate(stream);
                        }
                    }
                    if (certs != null) {
                        request.setAttribute
                            (AprEndpoint.CERTIFICATE_KEY, certs);
View Full Code Here

        {
            final String clientCert = HEADER_TO_CERT.matcher(clientCertHeader).replaceAll("\n");

            try
            {
                CertificateFactory fac = CertificateFactory.getInstance(X_509);

                InputStream instream = new ByteArrayInputStream(clientCert.getBytes(UTF_8));

                Collection<X509Certificate> certs = (Collection<X509Certificate>) fac.generateCertificates(instream);
                request.setAttribute(ATTR_SSL_CERTIFICATE, certs.toArray(new X509Certificate[certs.size()]));
            }
            catch (UnsupportedEncodingException e)
            {
                // Any JRE should support UTF-8...
View Full Code Here

    {
        final Collection result = new ArrayList();

        if (m_crlList.trim().length() != 0)
        {
            CertificateFactory fac = CertificateFactory.getInstance("X509");

            for (StringTokenizer tok = new StringTokenizer(m_crlList, "|"); tok
                .hasMoreElements();)
            {
                InputStream input = null;
                try
                {
                    input = m_action.getURLConnectionInputStream(m_action
                        .createURL(null, tok.nextToken(), null)
                        .openConnection());
                    result.addAll(fac.generateCRLs(input));
                }
                catch (Exception ex)
                {
                    // TODO: log this or something
                    ex.printStackTrace();
View Full Code Here

  }

  public X509Certificate[] parse(InputStream is) {
    List<X509Certificate> certs = Lists.newArrayList();
    try {
      CertificateFactory x509CertificateFactory = getX509CertificateFactory();
      while (is.available() > 0) {
        X509Certificate cert = (X509Certificate) x509CertificateFactory.generateCertificate(is);
        certs.add(cert);
      }
    } catch (CertificateException ce) {
      throw new IllegalArgumentException("Not an X509 certificate", ce);
    } catch (IOException e) {
View Full Code Here

    return toX509(certificate);
  }

  private static X509Certificate toX509(Certificate certificate) {
    try {
      CertificateFactory cf = CertificateFactory.getInstance("X.509");
      X509Certificate cert = (X509Certificate) cf.generateCertificate(new ByteArrayInputStream(certificate
          .getEncoded()));
      return cert;
    } catch (IOException e) {
      throw new IllegalArgumentException("Error converting certificate", e);
    } catch (CertificateException e) {
View Full Code Here

      KeyStore ks = KeyStore.getInstance("JKS");
      ks.load(null, new char[0]);

      is = getCert();

      CertificateFactory cf = CertificateFactory.getInstance("X.509");
      Collection<? extends Certificate> c = cf.generateCertificates(is);
      Iterator<? extends Certificate> it = c.iterator();
      while(it.hasNext()) {
        Certificate cert = it.next();
        ks.setCertificateEntry(cert.getPublicKey().toString(), cert);
      }
View Full Code Here

            // Initialize an new empty keystore
            KeyStore ks  = KeyStore.getInstance(KeyStore.getDefaultType());
            ks.load(null, new char[0]);

            log.log(Level.FINE, "read ca certificate from {0}", caCertFile);
            CertificateFactory certFac = CertificateFactory.getInstance("X.509");

            InputStream in = new FileInputStream(caCertFile);

            try {
                X509Certificate cert = (X509Certificate)certFac.generateCertificate(in);
                ks.setCertificateEntry(CA_ALIAS, cert);
                caCertificate = cert;
            } finally {
                try {
                    in.close();
                } catch(IOException ioe) {
                    // Ignore
                }
            }

            PKIXBuilderParameters pkixParams = new PKIXBuilderParameters(ks, new X509CertSelector());

            if (caCrlFile.exists()) {
                log.log(Level.FINE, "read certificate revocation list from {0}", caCrlFile);
                in = new FileInputStream(caCrlFile);

                try {
                    Collection crls = certFac.generateCRLs(in);

                    CollectionCertStoreParameters certStoreParams = new CollectionCertStoreParameters(crls);
                    CertStore certStore = CertStore.getInstance("Collection", certStoreParams);

                    pkixParams.setRevocationEnabled(true);
View Full Code Here

TOP

Related Classes of java.security.cert.CertificateFactory

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.