Package javax.security.cert

Examples of javax.security.cert.X509Certificate


        socket.setNeedClientAuth(true);
        socket.startHandshake();
    }

    private Object[] getX509Certs() {
        X509Certificate certs[] = null;
        try {
            certs = session.getPeerCertificateChain();
        } catch (Throwable ex) {
            // Get rid of the warning in the logs when no Client-Cert is
            // available
View Full Code Here


        if (session == null && requires != 0) throw new NO_PERMISSION("Missing required SSL session");

        try {
            if (log.isDebugEnabled()) log.debug("Scraping principal from SSL session");

            X509Certificate link = session.getPeerCertificateChain()[0];
            Subject subject = new Subject();
            String name = link.getSubjectDN().toString();

            if (log.isDebugEnabled()) log.debug("Obtained principal " + name);

            subject.getPrincipals().add(new X500Principal(name));
View Full Code Here

     * @throws Exception if the certificate chain cannot be verified
     */
    protected void verify(String host, SSLSession session) throws Exception {

        X509Certificate[] chain;
        X509Certificate   certificate;
        Principal         principal;
        PublicKey         publicKey;
        String            DN;
        String            CN;
        int               start;
        int               end;
        String            emsg;

        chain       = session.getPeerCertificateChain();
        certificate = chain[0];
        principal   = certificate.getSubjectDN();
        DN          = String.valueOf(principal);
        start       = DN.indexOf("CN=");

        if (start < 0) {
            throw new UnknownHostException(
View Full Code Here

        return getPeerCertificateChain(false);
    }

    protected java.security.cert.X509Certificate []
  getX509Certificates(SSLSession session) throws IOException {
        X509Certificate jsseCerts[] = null;
    try{
      jsseCerts = session.getPeerCertificateChain();
    } catch (Throwable ex){
       // Get rid of the warning in the logs when no Client-Cert is
       // available
View Full Code Here

        return getPeerCertificateChain(false);
    }

    protected java.security.cert.X509Certificate []
  getX509Certificates(SSLSession session) throws IOException {
        X509Certificate jsseCerts[] = null;
    try{
      jsseCerts = session.getPeerCertificateChain();
    } catch (Throwable ex){
       // Get rid of the warning in the logs when no Client-Cert is
       // available
View Full Code Here

     */
    protected void enrichWithClientCertInformation(SSLSession sslSession, Message message) {
        try {
            X509Certificate[] certificates = sslSession.getPeerCertificateChain();
            if (certificates != null && certificates.length > 0) {
                X509Certificate cert = certificates[0];

                Principal subject = cert.getSubjectDN();
                if (subject != null) {
                    message.setHeader(NettyConstants.NETTY_SSL_CLIENT_CERT_SUBJECT_NAME, subject.getName());
                }
                Principal issuer = cert.getIssuerDN();
                if (issuer != null) {
                    message.setHeader(NettyConstants.NETTY_SSL_CLIENT_CERT_ISSUER_NAME, issuer.getName());
                }
                BigInteger serial = cert.getSerialNumber();
                if (serial != null) {
                    message.setHeader(NettyConstants.NETTY_SSL_CLIENT_CERT_SERIAL_NO, serial.toString());
                }
                message.setHeader(NettyConstants.NETTY_SSL_CLIENT_CERT_NOT_BEFORE, cert.getNotBefore());
                message.setHeader(NettyConstants.NETTY_SSL_CLIENT_CERT_NOT_AFTER, cert.getNotAfter());
            }
        } catch (SSLPeerUnverifiedException e) {
            // ignore
        }
    }
View Full Code Here

     */
    protected void enrichWithClientCertInformation(SSLSession sslSession, Message message) {
        try {
            X509Certificate[] certificates = sslSession.getPeerCertificateChain();
            if (certificates != null && certificates.length > 0) {
                X509Certificate cert = certificates[0];

                Principal subject = cert.getSubjectDN();
                if (subject != null) {
                    message.setHeader(NettyConstants.NETTY_SSL_CLIENT_CERT_SUBJECT_NAME, subject.getName());
                }
                Principal issuer = cert.getIssuerDN();
                if (issuer != null) {
                    message.setHeader(NettyConstants.NETTY_SSL_CLIENT_CERT_ISSUER_NAME, issuer.getName());
                }
                BigInteger serial = cert.getSerialNumber();
                if (serial != null) {
                    message.setHeader(NettyConstants.NETTY_SSL_CLIENT_CERT_SERIAL_NO, serial.toString());
                }
                message.setHeader(NettyConstants.NETTY_SSL_CLIENT_CERT_NOT_BEFORE, cert.getNotBefore());
                message.setHeader(NettyConstants.NETTY_SSL_CLIENT_CERT_NOT_AFTER, cert.getNotAfter());
            }
        } catch (SSLPeerUnverifiedException e) {
            // ignore
        }
    }
View Full Code Here

     * @throws Exception if the certificate chain cannot be verified
     */
    protected void verify(String host, SSLSession session) throws Exception {

        X509Certificate[] chain;
        X509Certificate   certificate;
        Principal         principal;
        PublicKey         publicKey;
        String            DN;
        String            CN;
        int               start;
        int               end;
        String            emsg;

        chain       = session.getPeerCertificateChain();
        certificate = chain[0];
        principal   = certificate.getSubjectDN();
        DN          = String.valueOf(principal);
        start       = DN.indexOf("CN=");

        if (start < 0) {
            throw new UnknownHostException(
View Full Code Here

                 
                  try {
                     X509Certificate[] list = req.getClientCertificate().getChain();
                     StringBuilder builder = new StringBuilder();
                     for(X509Certificate cert : list) {
                        X509Certificate x509 = (X509Certificate)cert;
                        builder.append(x509);
                     }
                     certificateInfo = builder.toString();
                  } catch(Exception e) {
                     e.printStackTrace();
                     certificateInfo = e.getMessage();
                     challengeForCertificate = true;
                    
                     // http://stackoverflow.com/questions/14281628/ssl-renegotiation-with-client-certificate-causes-server-buffer-overflow
                     // Perhaps an expect 100 continue does something here?????
                     if(challengeForCertificate) {
                        Certificate certificate = req.getClientCertificate();                       
                        CertificateChallenge challenge = certificate.getChallenge();
                       
                        Future<Certificate> future = challenge.challenge(new Runnable() {
                           public void run() {
                              System.err.println("FINISHED THE CHALLENGE!!!");
                           }
                        });
                        Certificate futureCert = future.get(10, TimeUnit.SECONDS);
                       
                        if(futureCert == null) {
                           System.err.println("FAILED TO GET CERT!!!!");
                        } else {
                           System.err.println("**** GOT THE CERT");
                        }
                       
                        String text=  "Challenge finished without cert";
                        try {
                           X509Certificate[] list = req.getClientCertificate().getChain();
                           StringBuilder builder = new StringBuilder();
                           for(X509Certificate x509 : list) {
                              builder.append(x509);
                           }
                           text = builder.toString();
                        } catch(Exception ex) {
                           e.printStackTrace();
                        }
                        out.print(text);
                        out.flush();
                        try {
                           resp.close();
                        } catch(Exception ex){
                           e.printStackTrace();
                        }
                     }
                  }                 
                //  Thread.sleep(10000);
                  if(!challengeForCertificate) {
                     try {
                        X509Certificate[] list = req.getClientCertificate().getChain();
                        StringBuilder builder = new StringBuilder();
                        for(X509Certificate cert : list) {
                           X509Certificate x509 = (X509Certificate)cert;
                           builder.append(x509);
                        }
                        certificateInfo = builder.toString();
                     } catch(Exception e) {
                        e.printStackTrace();
View Full Code Here

                                              cached);
            return;
        }

        // Convert JSSE's certificate format to the ones we need
        X509Certificate jsseCerts[] = null;
        java.security.cert.X509Certificate x509Certs[] = null;
        try {
            jsseCerts = session.getPeerCertificateChain();
            if (jsseCerts == null)
                jsseCerts = new X509Certificate[0];
View Full Code Here

TOP

Related Classes of javax.security.cert.X509Certificate

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.