org.eclipse.ecf.ssl_1.0.100.v20110531-2218

16:43:15.929 INFO  jd.cli.Main - Decompiling org.eclipse.ecf.ssl_1.0.100.v20110531-2218.jar
package org.eclipse.ecf.internal.ssl;

import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;

public class ECFCertificateException
  extends CertificateException
{
  private static final long serialVersionUID = 3726926966308967473L;
  private X509Certificate[] certs;
  private String type;
  
  public ECFCertificateException(String msg, X509Certificate[] certs, String type)
  {
    super(msg);
    this.certs = certs;
    this.type = type;
  }
  
  public X509Certificate[] getCertificates()
  {
    return certs;
  }
  
  public String getType()
  {
    return type;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.ecf.internal.ssl.ECFCertificateException
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.ecf.internal.ssl;

import java.io.IOException;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;
import java.security.SecureRandom;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.TrustManager;

public class ECFSSLSocketFactory
  extends SSLSocketFactory
{
  public static final String DEFAULT_SSL_PROTOCOL = "https.protocols";
  private SSLContext sslContext = null;
  private String defaultProtocolNames = System.getProperty("https.protocols");
  
  private SSLSocketFactory getSSLSocketFactory()
    throws IOException
  {
    if (sslContext == null) {
      try
      {
        sslContext = getSSLContext(defaultProtocolNames);
      }
      catch (Exception e)
      {
        IOException ioe = new IOException();
        ioe.initCause(e);
        throw ioe;
      }
    }
    return sslContext == null ? (SSLSocketFactory)
      SSLSocketFactory.getDefault() : sslContext.getSocketFactory();
  }
  
  public SSLContext getSSLContext(String protocols)
  {
    SSLContext rtvContext = null;
    if (protocols != null)
    {
      String[] protocolNames = protocols.split(",");
      for (int i = 0; i < protocolNames.length; i++) {
        try
        {
          rtvContext = SSLContext.getInstance(protocolNames[i]);
          rtvContext.init(null, 
            new TrustManager[] { new ECFTrustManager() }, 
            new SecureRandom());
        }
        catch (Exception localException) {}
      }
    }
    return rtvContext;
  }
  
  public Socket createSocket()
    throws IOException
  {
    return getSSLSocketFactory().createSocket();
  }
  
  public Socket createSocket(Socket socket, String host, int port, boolean autoClose)
    throws IOException
  {
    return 
      getSSLSocketFactory().createSocket(socket, host, port, autoClose);
  }
  
  public String[] getDefaultCipherSuites()
  {
    try
    {
      return getSSLSocketFactory().getDefaultCipherSuites();
    }
    catch (IOException e) {}
    return new String[0];
  }
  
  public String[] getSupportedCipherSuites()
  {
    try
    {
      return getSSLSocketFactory().getSupportedCipherSuites();
    }
    catch (IOException e) {}
    return new String[0];
  }
  
  public Socket createSocket(String host, int port)
    throws IOException, UnknownHostException
  {
    return getSSLSocketFactory().createSocket(host, port);
  }
  
  public Socket createSocket(InetAddress address, int port)
    throws IOException
  {
    return getSSLSocketFactory().createSocket(address, port);
  }
  
  public Socket createSocket(InetAddress address, int port, InetAddress arg2, int arg3)
    throws IOException
  {
    return getSSLSocketFactory().createSocket(address, port);
  }
  
  public Socket createSocket(String host, int port, InetAddress address, int localPort)
    throws IOException, UnknownHostException
  {
    return getSSLSocketFactory().createSocket(host, port, address, 
      localPort);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.ecf.internal.ssl.ECFSSLSocketFactory
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.ecf.internal.ssl;

import java.io.IOException;
import java.security.Principal;
import java.security.cert.Certificate;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.X509TrustManager;
import org.eclipse.osgi.service.security.TrustEngine;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.util.tracker.ServiceTracker;

public class ECFTrustManager
  implements X509TrustManager, BundleActivator
{
  private static volatile BundleContext context;
  private volatile ServiceTracker trustEngineTracker = null;
  
  public void checkServerTrusted(X509Certificate[] certs, String authType)
    throws CertificateException
  {
    verify(certs, authType);
    
    TrustEngine[] engines = getTrustEngines();
    Certificate foundCert = null;
    for (int i = 0; i < engines.length; i++) {
      try
      {
        foundCert = engines[i].findTrustAnchor(certs);
        if (foundCert != null) {
          return;
        }
      }
      catch (IOException e)
      {
        CertificateException ce = new ECFCertificateException("Error occurs when finding trust anchor in the cert chain", certs, authType);
        ce.initCause(ce);
        throw ce;
      }
    }
    throw new ECFCertificateException("Valid cert chain, but no trust certificate found!", certs, authType);
  }
  
  private void verify(X509Certificate[] certs, String authType)
    throws CertificateException
  {
    int len = certs.length;
    for (int i = 0; i < len; i++)
    {
      X509Certificate currentX509Cert = certs[i];
      try
      {
        if (i == len - 1)
        {
          if (currentX509Cert.getSubjectDN().equals(currentX509Cert.getIssuerDN())) {
            currentX509Cert.verify(currentX509Cert.getPublicKey());
          }
        }
        else
        {
          X509Certificate nextX509Cert = certs[(i + 1)];
          currentX509Cert.verify(nextX509Cert.getPublicKey());
        }
      }
      catch (Exception e)
      {
        CertificateException ce = new ECFCertificateException("Certificate chain is not valid", certs, authType);
        ce.initCause(e);
        throw ce;
      }
    }
  }
  
  public void checkClientTrusted(X509Certificate[] arg0, String arg1)
    throws CertificateException
  {
    throw new UnsupportedOperationException("Not implemented yet");
  }
  
  public X509Certificate[] getAcceptedIssuers()
  {
    return null;
  }
  
  public void start(BundleContext context1)
    throws Exception
  {
    context = context1;
    context1.registerService(SSLSocketFactory.class.getName(), new ECFSSLSocketFactory(), null);
  }
  
  public void stop(BundleContext context1)
    throws Exception
  {
    if (trustEngineTracker != null)
    {
      trustEngineTracker.close();
      trustEngineTracker = null;
    }
    context = null;
  }
  
  private TrustEngine[] getTrustEngines()
  {
    if (trustEngineTracker == null)
    {
      trustEngineTracker = new ServiceTracker(context, TrustEngine.class.getName(), null);
      trustEngineTracker.open();
    }
    Object[] objs = trustEngineTracker.getServices();
    TrustEngine[] result = new TrustEngine[objs.length];
    System.arraycopy(objs, 0, result, 0, objs.length);
    return result;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.ecf.internal.ssl.ECFTrustManager
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
1

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2017. Infinite Loop Ltd