org.eclipse.osgi_3.8.2.v20130124-134944

port org.eclipse.osgi.service.resolver.DisabledInfo;
import org.eclipse.osgi.service.resolver.State;
import org.eclipse.osgi.signedcontent.SignedContent;
import org.eclipse.osgi.signedcontent.SignerInfo;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Version;

public class DefaultAuthorizationEngine
  extends AuthorizationEngine
{
  private static final String VERSION_PROP = "Version";
  private static final String VERSION_NUM = "1.0";
  private static final Version VERSION_MAX = new Version(2, 0, 0);
  private final State systemState;
  private final BundleContext bundleContext;
  public static final int ENFORCE_NONE = 0;
  public static final int ENFORCE_SIGNED = 1;
  public static final int ENFORCE_TRUSTED = 2;
  public static final int ENFORCE_VALIDITY = 4;
  private static final String STR_ENFORCE_NONE = "any";
  private static final String STR_ENFORCE_SIGNED = "signed";
  private static final String STR_ENFORCE_TRUSTED = "trusted";
  private static final String STR_ENFORCE_VALIDITY = "validity";
  private static final String POLICY_NAME = "org.eclipse.equinox.security";
  private static final String POLICY_PROP = "osgi.signedcontent.authorization.engine.policy";
  private static final String FILE_LOAD_POLICY = ".loadpolicy";
  private static int enforceFlags = 0;
  private static final File policyFile;
  
  static
  {
    File osgiFile = LocationManager.getOSGiConfigurationDir();
    policyFile = new File(osgiFile.getPath() + File.separatorChar + ".loadpolicy");
    
    Properties properties = null;
    if (policyFile.exists()) {
      try
      {
        properties = new Properties();
        properties.load(new FileInputStream(policyFile));
      }
      catch (IOException e)
      {
        SignedBundleHook.log("Error loading policy file", 4, e);
      }
    }
    if (properties != null)
    {
      Version version = new Version(0, 0, 0);
      String versionProp = properties.getProperty("Version");
      if (versionProp != null) {
        try
        {
          version = new Version(versionProp);
        }
        catch (IllegalArgumentException localIllegalArgumentException) {}
      }
      if (VERSION_MAX.compareTo(version) > 0)
      {
        String policy = properties.getProperty("osgi.signedcontent.authorization.engine.policy");
        if (policy != null) {
          try
          {
            enforceFlags = Integer.parseInt(policy);
          }
          catch (NumberFormatException localNumberFormatException) {}
        }
      }
    }
    else
    {
      String policy = FrameworkProperties.getProperty("osgi.signedcontent.authorization.engine.policy");
      if ((policy == null) || ("any".equals(policy))) {
        enforceFlags = 0;
      } else if ("trusted".equals(policy)) {
        enforceFlags = 3;
      } else if ("signed".equals(policy)) {
        enforceFlags = 1;
      } else if ("validity".equals(policy)) {
        enforceFlags = 7;
      }
    }
  }
  
  public DefaultAuthorizationEngine(BundleContext context, State systemState)
  {
    super(context);
    bundleContext = context;
    this.systemState = systemState;
  }
  
  protected AuthorizationEvent doAuthorize(SignedContent content, Object context)
  {
    boolean enabled = isEnabled(content, context);
    AuthorizationEvent event = null;
    if ((context instanceof Bundle))
    {
      BundleDescription desc = systemState.getBundle(((Bundle)context).getBundleId());
      if (!enabled)
      {
        DisabledInfo info = new DisabledInfo("org.eclipse.equinox.security", null, desc);
        systemState.addDisabledInfo(info);
        event = new AuthorizationEvent(1, content, context, 0);
      }
      else
      {
        DisabledInfo info = systemState.getDisabledInfo(desc, "org.eclipse.equinox.security");
        if (info != null) {
          systemState.removeDisabledInfo(info);
        }
        event = new AuthorizationEvent(0, content, context, 0);
      }
    }
    return event;
  }
  
  private boolean isEnabled(SignedContent content, Object context)
  {
    if (((context instanceof Bundle)) && (DevClassPathHelper.inDevelopmentMode()))
    {
      String[] devClassPath = DevClassPathHelper.getDevClassPath(((Bundle)context).getSymbolicName());
      if ((devClassPath != null) && (devClassPath.length > 0)) {
        return true;
      }
    }
    if (((enforceFlags & 0x1) != 0) && ((content == null) || (!content.isSigned()))) {
      return false;
    }
    SignerInfo[] signerInfos = content == null ? new SignerInfo[0] : content.getSignerInfos();
    for (int i = 0; i < signerInfos.length; i++)
    {
      if (((enforceFlags & 0x2) != 0) && (!signerInfos[i].isTrusted())) {
        return false;
      }
      if ((enforceFlags & 0x4) != 0) {
        try
        {
          content.checkValidity(signerInfos[i]);
        }
        catch (CertificateException localCertificateException)
        {
          return false;
        }
      }
    }
    return true;
  }
  
  public int getStatus()
  {
    if (systemState.getDisabledBundles().length != 0) {
      return 1;
    }
    return 0;
  }
  
  public void processInstalledBundles()
  {
    Bundle[] bundles = bundleContext.getBundles();
    for (int i = 0; i < bundles.length; i++)
    {
      BaseData baseData = (BaseData)((AbstractBundle)bundles[i]).getBundleData();
      SignedStorageHook hook = (SignedStorageHook)baseData.getStorageHook(SignedStorageHook.KEY);
      SignedContent signedContent = hook != null ? hook.getSignedContent() : null;
      authorize(signedContent, bundles[i]);
    }
  }
  
  public void setLoadPolicy(int policy)
  {
    if ((policy | 0x1 | 0x2 | 0x4) != 7) {
      throw new IllegalArgumentException("Invalid policy: " + policy);
    }
    enforceFlags = policy;
    Properties properties = new Properties();
    properties.setProperty("osgi.signedcontent.authorization.engine.policy", Integer.toString(policy));
    properties.setProperty("Version", "1.0");
    try
    {
      properties.store(new FileOutputStream(policyFile), null);
    }
    catch (IOException e)
    {
      SignedBundleHook.log("Error saving load policy file", 4, e);
    }
  }
  
  public int getLoadPolicy()
  {
    return enforceFlags;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.osgi.internal.service.security.DefaultAuthorizationEngine
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.osgi.internal.service.security;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.security.GeneralSecurityException;
import java.security.InvalidKeyException;
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.Principal;
import java.security.SignatureException;
import java.security.cert.Certificate;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import org.eclipse.osgi.internal.signedcontent.SignedBundleHook;
import org.eclipse.osgi.internal.signedcontent.SignedContentMessages;
import org.eclipse.osgi.service.security.TrustEngine;

public class KeyStoreTrustEngine
  extends TrustEngine
{
  private KeyStore keyStore;
  private final String type;
  private final String path;
  private final char[] password;
  private final String name;
  
  public KeyStoreTrustEngine(String path, String type, char[] password, String name)
  {
    this.path = path;
    this.type = type;
    this.password = password;
    this.name = name;
  }
  
  private String getType()
  {
    return type;
  }
  
  private String getPath()
  {
    return path;
  }
  
  private char[] getPassword()
  {
    return password;
  }
  
  /* Error */
  private synchronized KeyStore getKeyStore()
    throws IOException, GeneralSecurityException
  {
    // Byte code:
    //   0: aload_0
    //   1: getfield 244	org/eclipse/osgi/internal/service/security/KeyStoreTrustEngine:keyStore	Ljava/security/KeyStore;
    //   4: ifnonnull +50 -> 54
    //   7: aload_0
    //   8: aload_0
    //   9: invokespecial 288	org/eclipse/osgi/internal/service/security/KeyStoreTrustEngine:getType	()Ljava/lang/String;
    //   12: invokestatic 268	java/security/KeyStore:getInstance	(Ljava/lang/String;)Ljava/security/KeyStore;
    //   15: putfield 244	org/eclipse/osgi/internal/service/security/KeyStoreTrustEngine:keyStore	Ljava/security/KeyStore;
    //   18: aload_0
    //   19: invokespecial 284	org/eclipse/osgi/internal/service/security/KeyStoreTrustEngine:getInputStream	()Ljava/io/InputStream;
    //   22: astore_1
    //   23: aload_0
    //   24: aload_0
    //   25: getfield 244	org/eclipse/osgi/internal/service/security/KeyStoreTrustEngine:keyStore	Ljava/security/KeyStore;
    //   28: aload_1
    //   29: invokespecial 291	org/eclipse/osgi/internal/service/security/KeyStoreTrustEngine:loadStore	(Ljava/security/KeyStore;Ljava/io/InputStream;)V
    //   32: goto +14 -> 46
    //   35: astore_2
    //   36: aload_1
    //   37: invokevirtual 258	java/io/InputStream:close	()V
    //   40: goto +4 -> 44
    //   43: pop
    //   44: aload_2
    //   45: athrow
    //   46: aload_1
    //   47: invokevirtual 258	java/io/InputStream:close	()V
    //   50: goto +4 -> 54
    //   53: pop
    //   54: aload_0
    //   55: getfield 244	org/eclipse/osgi/internal/service/security/KeyStoreTrustEngine:keyStore	Ljava/security/KeyStore;
    //   58: ifnonnull +21 -> 79
    //   61: new 127	java/security/KeyStoreException
    //   64: dup
    //   65: getstatic 248	org/eclipse/osgi/internal/signedcontent/SignedContentMessages:Default_Trust_Keystore_Load_Failed	Ljava/lang/String;
    //   68: aload_0
    //   69: invokespecial 287	org/eclipse/osgi/internal/service/security/KeyStoreTrustEngine:getPath	()Ljava/lang/String;
    //   72: invokestatic 296	org/eclipse/osgi/util/NLS:bind	(Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/String;
    //   75: invokespecial 272	java/security/KeyStoreException:<init>	(Ljava/lang/String;)V
    //   78: athrow
    //   79: aload_0
    //   80: getfield 244	org/eclipse/osgi/internal/service/security/KeyStoreTrustEngine:keyStore	Ljava/security/KeyStore;
    //   83: areturn
    // Line number table:
    //   Java source line #85	-> byte code offset #0
    //   Java source line #86	-> byte code offset #7
    //   Java source line #87	-> byte code offset #18
    //   Java source line #89	-> byte code offset #23
    //   Java source line #90	-> byte code offset #32
    //   Java source line #92	-> byte code offset #36
    //   Java source line #93	-> byte code offset #40
    //   Java source line #96	-> byte code offset #44
    //   Java source line #92	-> byte code offset #46
    //   Java source line #93	-> byte code offset #50
    //   Java source line #99	-> byte code offset #54
    //   Java source line #100	-> byte code offset #61
    //   Java source line #102	-> byte code offset #79
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	84	0	this	KeyStoreTrustEngine
    //   22	25	1	in	InputStream
    //   35	10	2	localObject	Object
    //   43	1	3	localIOException1	IOException
    //   53	1	4	localIOException2	IOException
    // Exception table:
    //   from	to	target	type
    //   23	35	35	finally
    //   36	40	43	java/io/IOException
    //   46	50	53	java/io/IOException
  }
  
  public Certificate findTrustAnchor(Certificate[] certChain)
    throws IOException
  {
    if ((certChain == null) || (certChain.length == 0)) {
      throw new IllegalArgumentException("Certificate chain is required");
    }
    try
    {
      Certificate rootCert = null;
      KeyStore store = getKeyStore();
      for (int i = 0; i < certChain.length; i++)
      {
        if ((certChain[i] instanceof X509Certificate)) {
          if (i == certChain.length - 1)
          {
            X509Certificate cert = (X509Certificate)certChain[i];
            if (cert.getSubjectDN().equals(cert.getIssuerDN()))
            {
              cert.verify(cert.getPublicKey());
              rootCert = cert;
            }
            else
            {
              return findAlternativeRoot(cert, store);
            }
          }
          else
          {
            X509Certificate nextX509Cert = (X509Certificate)certChain[(i + 1)];
            certChain[i].verify(nextX509Cert.getPublicKey());
          }
        }
        synchronized (store)
        {
          String alias = rootCert == null ? null : store.getCertificateAlias(rootCert);
          if (alias != null) {
            return store.getCertificate(alias);
          }
          if (rootCert != certChain[i])
          {
            alias = store.getCertificateAlias(certChain[i]);
            if (alias != null) {
              return store.getCertificate(alias);
            }
          }
          if ((certChain.length > 1) && (i == certChain.length - 1) && ((certChain[(i - 1)] instanceof X509Certificate))) {
            return findAlternativeRoot((X509Certificate)certChain[(i - 1)], store);
          }
        }
      }
    }
    catch (KeyStoreException e)
    {
      throw ((IOException)new IOException(e.getMessage()).initCause(e));
    }
    catch (GeneralSecurityException e)
    {
      SignedBundleHook.log(e.getMessage(), 2, e);
      return null;
    }
    return null;
  }
  
  private Certificate findAlternativeRoot(X509Certificate cert, KeyStore store)
    throws InvalidKeyException, KeyStoreException, NoSuchAlgorithmException, NoSuchProviderException, SignatureException, CertificateException
  {
    synchronized (store)
    {
      for (Enumeration<String> e = store.aliases(); e.hasMoreElements();)
      {
        Certificate nextCert = store.getCertificate((String)e.nextElement());
        if (((nextCert instanceof X509Certificate)) && (((X509Certificate)nextCert).getSubjectDN().equals(cert.getIssuerDN())))
        {
          cert.verify(nextCert.getPublicKey());
          return nextCert;
        }
      }
      return null;
    }
  }
  
  /* Error */
  protected String doAddTrustAnchor(Certificate cert, String alias)
    throws IOException, GeneralSecurityException
  {
    // Byte code:
    //   0: aload_0
    //   1: invokevirtual 282	org/eclipse/osgi/internal/service/security/KeyStoreTrustEngine:isReadOnly	()Z
    //   4: ifeq +14 -> 18
    //   7: new 119	java/io/IOException
    //   10: dup
    //   11: getstatic 249	org/eclipse/osgi/internal/signedcontent/SignedContentMessages:Default_Trust_Read_Only	Ljava/lang/String;
    //   14: invokespecial 256	java/io/IOException:<init>	(Ljava/lang/String;)V
    //   17: athrow
    //   18: aload_1
    //   19: ifnonnull +13 -> 32
    //   22: new 122	java/lang/IllegalArgumentException
    //   25: dup
    //   26: ldc 3
    //   28: invokespecial 260	java/lang/IllegalArgumentException:<init>	(Ljava/lang/String;)V
    //   31: athrow
    //   32: aload_0
    //   33: invokespecial 290	org/eclipse/osgi/internal/service/security/KeyStoreTrustEngine:getKeyStore	()Ljava/security/KeyStore;
    //   36: astore_3
    //   37: aload_3
    //   38: dup
    //   39: astore 4
    //   41: monitorenter
    //   42: aload_3
    //   43: aload_1
    //   44: invokevirtual 267	java/security/KeyStore:getCertificateAlias	(Ljava/security/cert/Certificate;)Ljava/lang/String;
    //   47: astore 5
    //   49: aload 5
    //   51: ifnull +14 -> 65
    //   54: new 133	java/security/cert/CertificateException
    //   57: dup
    //   58: getstatic 247	org/eclipse/osgi/internal/signedcontent/SignedContentMessages:Default_Trust_Existing_Cert	Ljava/lang/String;
    //   61: invokespecial 275	java/security/cert/CertificateException:<init>	(Ljava/lang/String;)V
    //   64: athrow
    //   65: aload_3
    //   66: aload_2
    //   67: invokevirtual 269	java/security/KeyStore:getCertificate	(Ljava/lang/String;)Ljava/security/cert/Certificate;
    //   70: astore 6
    //   72: aload 6
    //   74: ifnull +14 -> 88
    //   77: new 133	java/security/cert/CertificateException
    //   80: dup
    //   81: getstatic 246	org/eclipse/osgi/internal/signedcontent/SignedContentMessages:Default_Trust_Existing_Alias	Ljava/lang/String;
    //   84: invokespecial 275	java/security/cert/CertificateException:<init>	(Ljava/lang/String;)V
    //   87: athrow
    //   88: aload_3
    //   89: aload_2
    //   90: aload_1
    //   91: invokevirtual 270	java/security/KeyStore:setCertificateEntry	(Ljava/lang/String;Ljava/security/cert/Certificate;)V
    //   94: aload_0
    //   95: invokespecial 285	org/eclipse/osgi/internal/service/security/KeyStoreTrustEngine:getOutputStream	()Ljava/io/OutputStream;
    //   98: astore 7
    //   100: aload_0
    //   101: aload_3
    //   102: aload 7
    //   104: invokespecial 292	org/eclipse/osgi/internal/service/security/KeyStoreTrustEngine:saveStore	(Ljava/security/KeyStore;Ljava/io/OutputStream;)V
    //   107: goto +14 -> 121
    //   110: astore 8
    //   112: aload_0
    //   113: aload 7
    //   115: invokespecial 286	org/eclipse/osgi/internal/service/security/KeyStoreTrustEngine:safeClose	(Ljava/io/OutputStream;)V
    //   118: aload 8
    //   120: athrow
    //   121: aload_0
    //   122: aload 7
    //   124: invokespecial 286	org/eclipse/osgi/internal/service/security/KeyStoreTrustEngine:safeClose	(Ljava/io/OutputStream;)V
    //   127: aload 4
    //   129: monitorexit
    //   130: goto +27 -> 157
    //   133: aload 4
    //   135: monitorexit
    //   136: athrow
    //   137: astore_3
    //   138: new 133	java/security/cert/CertificateException
    //   141: dup
    //   142: aload_3
    //   143: invokevirtual 271	java/security/KeyStoreException:getMessage	()Ljava/lang/String;
    //   146: invokespecial 275	java/security/cert/CertificateException:<init>	(Ljava/lang/String;)V
    //   149: aload_3
    //   150: invokevirtual 276	java/security/cert/CertificateException:initCause	(Ljava/lang/Throwable;)Ljava/lang/Throwable;
    //   153: checkcast 133	java/security/cert/CertificateException
    //   156: athrow
    //   157: aload_2
    //   158: areturn
    // Line number table:
    //   Java source line #170	-> byte code offset #0
    //   Java source line #171	-> byte code offset #7
    //   Java source line #172	-> byte code offset #18
    //   Java source line #173	-> byte code offset #22
    //   Java source line #176	-> byte code offset #32
    //   Java source line #177	-> byte code offset #37
    //   Java source line #178	-> byte code offset #42
    //   Java source line #179	-> byte code offset #49
    //   Java source line #180	-> byte code offset #54
    //   Java source line #181	-> byte code offset #65
    //   Java source line #182	-> byte code offset #72
    //   Java source line #183	-> byte code offset #77
    //   Java source line #184	-> byte code offset #88
    //   Java source line #185	-> byte code offset #94
    //   Java source line #187	-> byte code offset #100
    //   Java source line #188	-> byte code offset #107
    //   Java source line #189	-> byte code offset #112
    //   Java source line #190	-> byte code offset #118
    //   Java source line #189	-> byte code offset #121
    //   Java source line #177	-> byte code offset #127
    //   Java source line #192	-> byte code offset #137
    //   Java source line #193	-> byte code offset #138
    //   Java source line #195	-> byte code offset #157
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	159	0	this	KeyStoreTrustEngine
    //   0	159	1	cert	Certificate
    //   0	159	2	alias	String
    //   36	66	3	store	KeyStore
    //   137	13	3	ke	KeyStoreException
    //   39	95	4	Ljava/lang/Object;	Object
    //   47	3	5	oldAlias	String
    //   70	3	6	oldCert	Certificate
    //   98	25	7	out	OutputStream
    //   110	9	8	localObject1	Object
    // Exception table:
    //   from	to	target	type
    //   100	110	110	finally
    //   42	130	133	finally
    //   133	136	133	finally
    //   32	137	137	java/security/KeyStoreException
  }
  
  protected void doRemoveTrustAnchor(Certificate cert)
    throws IOException, GeneralSecurityException
  {
    if (isReadOnly()) {
      throw new IOException(SignedContentMessages.Default_Trust_Read_Only);
    }
    if (cert == null) {
      throw new IllegalArgumentException("Certificate must be specified");
    }
    try
    {
      KeyStore store = getKeyStore();
      synchronized (store)
      {
        String alias = store.getCertificateAlias(cert);
        if (alias == null) {
          throw new CertificateException(SignedContentMessages.Default_Trust_Cert_Not_Found);
        }
        removeTrustAnchor(alias);
      }
    }
    catch (KeyStoreException ke)
    {
      throw ((CertificateException)new CertificateException(ke.getMessage()).initCause(ke));
    }
  }
  
  /* Error */
  protected void doRemoveTrustAnchor(String alias)
    throws IOException, GeneralSecurityException
  {
    // Byte code:
    //   0: aload_1
    //   1: ifnonnull +13 -> 14
    //   4: new 122	java/lang/IllegalArgumentException
    //   7: dup
    //   8: ldc 1
    //   10: invokespecial 260	java/lang/IllegalArgumentException:<init>	(Ljava/lang/String;)V
    //   13: athrow
    //   14: aload_0
    //   15: invokespecial 290	org/eclipse/osgi/internal/service/security/KeyStoreTrustEngine:getKeyStore	()Ljava/security/KeyStore;
    //   18: astore_2
    //   19: aload_2
    //   20: dup
    //   21: astore_3
    //   22: monitorenter
    //   23: aload_2
    //   24: aload_1
    //   25: invokevirtual 269	java/security/KeyStore:getCertificate	(Ljava/lang/String;)Ljava/security/cert/Certificate;
    //   28: astore 4
    //   30: aload 4
    //   32: ifnonnull +14 -> 46
    //   35: new 133	java/security/cert/CertificateException
    //   38: dup
    //   39: getstatic 245	org/eclipse/osgi/internal/signedcontent/SignedContentMessages:Default_Trust_Cert_Not_Found	Ljava/lang/String;
    //   42: invokespecial 275	java/security/cert/CertificateException:<init>	(Ljava/lang/String;)V
    //   45: athrow
    //   46: aload_2
    //   47: aload_1
    //   48: invokevirtual 264	java/security/KeyStore:deleteEntry	(Ljava/lang/String;)V
    //   51: aload_0
    //   52: invokespecial 285	org/eclipse/osgi/internal/service/security/KeyStoreTrustEngine:getOutputStream	()Ljava/io/OutputStream;
    //   55: astore 5
    //   57: aload_0
    //   58: aload_2
    //   59: aload 5
    //   61: invokespecial 292	org/eclipse/osgi/internal/service/security/KeyStoreTrustEngine:saveStore	(Ljava/security/KeyStore;Ljava/io/OutputStream;)V
    //   64: goto +14 -> 78
    //   67: astore 6
    //   69: aload_0
    //   70: aload 5
    //   72: invokespecial 286	org/eclipse/osgi/internal/service/security/KeyStoreTrustEngine:safeClose	(Ljava/io/OutputStream;)V
    //   75: aload 6
    //   77: athrow
    //   78: aload_0
    //   79: aload 5
    //   81: invokespecial 286	org/eclipse/osgi/internal/service/security/KeyStoreTrustEngine:safeClose	(Ljava/io/OutputStream;)V
    //   84: aload_3
    //   85: monitorexit
    //   86: goto +26 -> 112
    //   89: aload_3
    //   90: monitorexit
    //   91: athrow
    //   92: astore_2
    //   93: new 133	java/security/cert/CertificateException
    //   96: dup
    //   97: aload_2
    //   98: invokevirtual 271	java/security/KeyStoreException:getMessage	()Ljava/lang/String;
    //   101: invokespecial 275	java/security/cert/CertificateException:<init>	(Ljava/lang/String;)V
    //   104: aload_2
    //   105: invokevirtual 276	java/security/cert/CertificateException:initCause	(Ljava/lang/Throwable;)Ljava/lang/Throwable;
    //   108: checkcast 133	java/security/cert/CertificateException
    //   111: athrow
    //   112: return
    // Line number table:
    //   Java source line #220	-> byte code offset #0
    //   Java source line #221	-> byte code offset #4
    //   Java source line #224	-> byte code offset #14
    //   Java source line #225	-> byte code offset #19
    //   Java source line #226	-> byte code offset #23
    //   Java source line #227	-> byte code offset #30
    //   Java source line #228	-> byte code offset #35
    //   Java source line #229	-> byte code offset #46
    //   Java source line #230	-> byte code offset #51
    //   Java source line #232	-> byte code offset #57
    //   Java source line #233	-> byte code offset #64
    //   Java source line #234	-> byte code offset #69
    //   Java source line #235	-> byte code offset #75
    //   Java source line #234	-> byte code offset #78
    //   Java source line #225	-> byte code offset #84
    //   Java source line #237	-> byte code offset #92
    //   Java source line #238	-> byte code offset #93
    //   Java source line #240	-> byte code offset #112
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	113	0	this	KeyStoreTrustEngine
    //   0	113	1	alias	String
    //   18	41	2	store	KeyStore
    //   92	13	2	ke	KeyStoreException
    //   21	69	3	Ljava/lang/Object;	Object
    //   28	3	4	oldCert	Certificate
    //   55	25	5	out	OutputStream
    //   67	9	6	localObject1	Object
    // Exception table:
    //   from	to	target	type
    //   57	67	67	finally
    //   23	86	89	finally
    //   89	91	89	finally
    //   14	92	92	java/security/KeyStoreException
  }
  
  /* Error */
  public Certificate getTrustAnchor(String alias)
    throws IOException, GeneralSecurityException
  {
    // Byte code:
    //   0: aload_1
    //   1: ifnonnull +13 -> 14
    //   4: new 122	java/lang/IllegalArgumentException
    //   7: dup
    //   8: ldc 1
    //   10: invokespecial 260	java/lang/IllegalArgumentException:<init>	(Ljava/lang/String;)V
    //   13: athrow
    //   14: aload_0
    //   15: invokespecial 290	org/eclipse/osgi/internal/service/security/KeyStoreTrustEngine:getKeyStore	()Ljava/security/KeyStore;
    //   18: astore_2
    //   19: aload_2
    //   20: dup
    //   21: astore_3
    //   22: monitorenter
    //   23: aload_2
    //   24: aload_1
    //   25: invokevirtual 269	java/security/KeyStore:getCertificate	(Ljava/lang/String;)Ljava/security/cert/Certificate;
    //   28: aload_3
    //   29: monitorexit
    //   30: areturn
    //   31: aload_3
    //   32: monitorexit
    //   33: athrow
    //   34: astore_2
    //   35: new 133	java/security/cert/CertificateException
    //   38: dup
    //   39: aload_2
    //   40: invokevirtual 271	java/security/KeyStoreException:getMessage	()Ljava/lang/String;
    //   43: invokespecial 275	java/security/cert/CertificateException:<init>	(Ljava/lang/String;)V
    //   46: aload_2
    //   47: invokevirtual 276	java/security/cert/CertificateException:initCause	(Ljava/lang/Throwable;)Ljava/lang/Throwable;
    //   50: checkcast 133	java/security/cert/CertificateException
    //   53: athrow
    // Line number table:
    //   Java source line #244	-> byte code offset #0
    //   Java source line #245	-> byte code offset #4
    //   Java source line #249	-> byte code offset #14
    //   Java source line #250	-> byte code offset #19
    //   Java source line #251	-> byte code offset #23
    //   Java source line #250	-> byte code offset #31
    //   Java source line #253	-> byte code offset #34
    //   Java source line #254	-> byte code offset #35
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	54	0	this	KeyStoreTrustEngine
    //   0	54	1	alias	String
    //   18	6	2	store	KeyStore
    //   34	13	2	ke	KeyStoreException
    //   21	11	3	Ljava/lang/Object;	Object
    // Exception table:
    //   from	to	target	type
    //   23	30	31	finally
    //   31	33	31	finally
    //   14	30	34	java/security/KeyStoreException
    //   31	34	34	java/security/KeyStoreException
  }
  
  public String[] getAliases()
    throws IOException, GeneralSecurityException
  {
    List<String> returnList = new ArrayList();
    try
    {
      KeyStore store = getKeyStore();
      synchronized (store)
      {
        for (Enumeration<String> aliases = store.aliases(); aliases.hasMoreElements();)
        {
          String currentAlias = (String)aliases.nextElement();
          if (store.isCertificateEntry(currentAlias)) {
            returnList.add(currentAlias);
          }
        }
      }
    }
    catch (KeyStoreException ke)
    {
      throw ((CertificateException)new CertificateException(ke.getMessage()).initCause(ke));
    }
    return (String[])returnList.toArray(new String[0]);
  }
  
  private void loadStore(KeyStore store, InputStream is)
    throws IOException, GeneralSecurityException
  {
    store.load(is, getPassword());
  }
  
  private void saveStore(KeyStore store, OutputStream os)
    throws IOException, GeneralSecurityException
  {
    store.store(os, getPassword());
  }
  
  private void safeClose(OutputStream out)
  {
    try
    {
      if (out != null) {
        out.close();
      }
    }
    catch (IOException localIOException) {}
  }
  
  private InputStream getInputStream()
    throws IOException
  {
    return new FileInputStream(new File(getPath()));
  }
  
  private OutputStream getOutputStream()
    throws IOException
  {
    File file = new File(getPath());
    if (!file.exists()) {
      file.createNewFile();
    }
    return new FileOutputStream(file);
  }
  
  public boolean isReadOnly()
  {
    return (getPassword() == null) || (!new File(path).canWrite());
  }
  
  public String getName()
  {
    return name;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.osgi.internal.service.security.KeyStoreTrustEngine
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.osgi.internal.serviceregistry;

import org.eclipse.osgi.framework.debug.Debug;
import org.eclipse.osgi.framework.internal.core.BundleContextImpl;
import org.eclipse.osgi.framework.internal.core.FilterImpl;
import org.osgi.framework.AllServiceListener;
import org.osgi.framework.BundleContext;
import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.ServiceEvent;
import org.osgi.framework.ServiceListener;
import org.osgi.framework.ServiceReference;
import org.osgi.framework.UnfilteredServiceListener;
import org.osgi.framework.hooks.service.ListenerHook.ListenerInfo;

class FilteredServiceListener
  implements ServiceListener, ListenerHook.ListenerInfo
{
  private final FilterImpl filter;
  private final ServiceListener listener;
  private final BundleContextImpl context;
  private final boolean allservices;
  private final boolean unfiltered;
  private final String objectClass;
  private volatile boolean removed;
  
  FilteredServiceListener(BundleContextImpl context, ServiceListener listener, String filterstring)
    throws InvalidSyntaxException
  {
    unfiltered = (listener instanceof UnfilteredServiceListener);
    if (filterstring == null)
    {
      filter = null;
      objectClass = null;
    }
    else
    {
      FilterImpl filterImpl = FilterImpl.newInstance(filterstring);
      String clazz = filterImpl.getRequiredObjectClass();
      if ((unfiltered) || (clazz == null))
      {
        objectClass = null;
        filter = filterImpl;
      }
      else
      {
        objectClass = clazz.intern();
        filter = (filterstring.equals(getObjectClassFilterString(objectClass)) ? null : filterImpl);
      }
    }
    removed = false;
    this.listener = listener;
    this.context = context;
    allservices = (listener instanceof AllServiceListener);
  }
  
  public void serviceChanged(ServiceEvent event)
  {
    ServiceReferenceImpl<?> reference = (ServiceReferenceImpl)event.getServiceReference();
    if (objectClass != null)
    {
      String[] classes = reference.getClasses();
      int size = classes.length;
      int i = 0;
      while (classes[i] != objectClass)
      {
        i++;
        if (i >= size) {
          return;
        }
      }
    }
    if (!ServiceRegistry.hasListenServicePermission(event, context)) {
      return;
    }
    if (Debug.DEBUG_EVENTS)
    {
      String listenerName = getClass().getName() + "@" + Integer.toHexString(System.identityHashCode(this));
      Debug.println("filterServiceEvent(" + listenerName + ", \"" + getFilter() + "\", " + reference.getRegistration().getProperties() + ")");
    }
    event = filterMatch(event);
    if (event == null) {
      return;
    }
    if ((allservices) || (ServiceRegistry.isAssignableTo(context, reference)))
    {
      if (Debug.DEBUG_EVENTS)
      {
        String listenerName = listener.getClass().getName() + "@" + Integer.toHexString(System.identityHashCode(listener));
        Debug.println("dispatchFilteredServiceEvent(" + listenerName + ")");
      }
      listener.serviceChanged(event);
    }
  }
  
  private ServiceEvent filterMatch(ServiceEvent delivered)
  {
    boolean modified = delivered.getType() == 2;
    ServiceEvent event = modified ? ((ModifiedServiceEvent)delivered).getModifiedEvent() : delivered;
    if ((unfiltered) || (filter == null)) {
      return event;
    }
    ServiceReference<?> reference = event.getServiceReference();
    if (filter.match(reference)) {
      return event;
    }
    if (modified)
    {
      ModifiedServiceEvent modifiedServiceEvent = (ModifiedServiceEvent)delivered;
      if (modifiedServiceEvent.matchPreviousProperties(filter)) {
        return modifiedServiceEvent.getModifiedEndMatchEvent();
      }
    }
    return null;
  }
  
  public String toString()
  {
    String filterString = getFilter();
    if (filterString == null) {
      filterString = "";
    }
    return listener.getClass().getName() + "@" + Integer.toHexString(System.identityHashCode(listener)) + filterString;
  }
  
  public BundleContext getBundleContext()
  {
    return context;
  }
  
  public String getFilter()
  {
    if (filter != null) {
      return filter.toString();
    }
    return getObjectClassFilterString(objectClass);
  }
  
  public boolean isRemoved()
  {
    return removed;
  }
  
  void markRemoved()
  {
    removed = true;
  }
  
  private static String getObjectClassFilterString(String className)
  {
    if (className == null) {
      return null;
    }
    return "(objectClass=" + className + ")";
  }
}

/* Location:
 * Qualified Name:     org.eclipse.osgi.internal.serviceregistry.FilteredServiceListener
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.osgi.internal.serviceregistry;

import org.osgi.framework.ServiceRegistration;

public abstract interface HookContext
{
  public abstract void call(Object paramObject, ServiceRegistration<?> paramServiceRegistration)
    throws Exception;
  
  public abstract String getHookClassName();
  
  public abstract String getHookMethodName();
}

/* Location:
 * Qualified Name:     org.eclipse.osgi.internal.serviceregistry.HookContext
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.osgi.internal.serviceregistry;

import org.osgi.framework.Filter;
import org.osgi.framework.ServiceEvent;
import org.osgi.framework.ServiceReference;

class ModifiedServiceEvent
  extends ServiceEvent
{
  private static final long serialVersionUID = -5373850978543026102L;
  private final ServiceEvent modified;
  private final ServiceEvent modifiedEndMatch;
  private final ServiceProperties previousProperties;
  
  ModifiedServiceEvent(ServiceReference<?> reference, ServiceProperties previousProperties)
  {
    super(2, reference);
    modified = new ServiceEvent(2, reference);
    modifiedEndMatch = new ServiceEvent(8, reference);
    this.previousProperties = previousProperties;
  }
  
  ServiceEvent getModifiedEvent()
  {
    return modified;
  }
  
  ServiceEvent getModifiedEndMatchEvent()
  {
    return modifiedEndMatch;
  }
  
  boolean matchPreviousProperties(Filter filter)
  {
    return filter.matchCase(previousProperties);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.osgi.internal.serviceregistry.ModifiedServiceEvent
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.osgi.internal.serviceregistry;

import java.lang.reflect.Array;
import java.lang.reflect.Method;
import java.util.Dictionary;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Vector;
import org.eclipse.osgi.framework.util.Headers;

class ServiceProperties
  extends Headers<String, Object>
{
  private ServiceProperties(int size, Dictionary<String, ?> props)
  {
    super(size);
    if (props == null) {
      return;
    }
    synchronized (props)
    {
      Enumeration<?> keysEnum = props.keys();
      while (keysEnum.hasMoreElements())
      {
        Object key = keysEnum.nextElement();
        if ((key instanceof String))
        {
          String header = (String)key;
          
          setProperty(header, props.get(header));
        }
      }
    }
  }
  
  ServiceProperties(Dictionary<String, ?> props)
  {
    this(props == null ? 2 : props.size() + 2, props);
  }
  
  Object getProperty(String key)
  {
    return cloneValue(get(key));
  }
  
  synchronized String[] getPropertyKeys()
  {
    int size = size();
    
    String[] keynames = new String[size];
    
    Enumeration<String> keysEnum = keys();
    for (int i = 0; i < size; i++) {
      keynames[i] = ((String)keysEnum.nextElement());
    }
    return keynames;
  }
  
  synchronized Object setProperty(String key, Object value)
  {
    return set(key, cloneValue(value));
  }
  
  private static Object cloneValue(Object value)
  {
    if (value == null) {
      return null;
    }
    if ((value instanceof String)) {
      return value;
    }
    if ((value instanceof Number)) {
      return value;
    }
    if ((value instanceof Character)) {
      return value;
    }
    if ((value instanceof Boolean)) {
      return value;
    }
    Class<?> clazz = value.getClass();
    if (clazz.isArray())
    {
      Class<?> type = clazz.getComponentType();
      int len = Array.getLength(value);
      Object clonedArray = Array.newInstance(type, len);
      System.arraycopy(value, 0, clonedArray, 0, len);
      return clonedArray;
    }
    try
    {
      return clazz.getMethod("clone", null).invoke(value, null);
    }
    catch (Exception localException) {}catch (Error localError)
    {
      if ((value instanceof Vector)) {
        return ((Vector)value).clone();
      }
      if ((value instanceof Hashtable)) {
        return ((Hashtable)value).clone();
      }
    }
    return value;
  }
  
  public synchronized String toString()
  {
    String[] keys = getPropertyKeys();
    
    int size = keys.length;
    
    StringBuffer sb = new StringBuffer(20 * size);
    
    sb.append('{');
    
    int n = 0;
    for (int i = 0; i < size; i++)
    {
      String key = keys[i];
      if (!key.equals("objectClass"))
      {
        if (n > 0) {
          sb.append(", ");
        }
        sb.append(key);
        sb.append('=');
        Object value = get(key);
        if (value.getClass().isArray())
        {
          sb.append('[');
          int length = Array.getLength(value);
          for (int j = 0; j < length; j++)
          {
            if (j > 0) {
              sb.append(',');
            }
            sb.append(Array.get(value, j));
          }
          sb.append(']');
        }
        else
        {
          sb.append(value);
        }
        n++;
      }
    }
    sb.append('}');
    
    return sb.toString();
  }
}

/* Location:
 * Qualified Name:     org.eclipse.osgi.internal.serviceregistry.ServiceProperties
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.osgi.internal.serviceregistry;

import org.osgi.framework.Bundle;
import org.osgi.framework.ServiceReference;

public class ServiceReferenceImpl<S>
  implements ServiceReference<S>
{
  private final ServiceRegistrationImpl<S> registration;
  
  ServiceReferenceImpl(ServiceRegi
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87

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-2019. Infinite Loop Ltd