felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pa...@apache.org
Subject svn commit: r1366063 - in /felix/trunk/framework/src/main/java/org/apache/felix/framework: BundleImpl.java BundleProtectionDomain.java Felix.java
Date Thu, 26 Jul 2012 16:18:02 GMT
Author: pauls
Date: Thu Jul 26 16:18:02 2012
New Revision: 1366063

URL: http://svn.apache.org/viewvc?rev=1366063&view=rev
Log:
Fix a bug where we where not checking bundle signer signatures when restarting and set the
signers on the codesource of a bundle (FELIX-3610,FELIX-3611)

Modified:
    felix/trunk/framework/src/main/java/org/apache/felix/framework/BundleImpl.java
    felix/trunk/framework/src/main/java/org/apache/felix/framework/BundleProtectionDomain.java
    felix/trunk/framework/src/main/java/org/apache/felix/framework/Felix.java

Modified: felix/trunk/framework/src/main/java/org/apache/felix/framework/BundleImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/framework/src/main/java/org/apache/felix/framework/BundleImpl.java?rev=1366063&r1=1366062&r2=1366063&view=diff
==============================================================================
--- felix/trunk/framework/src/main/java/org/apache/felix/framework/BundleImpl.java (original)
+++ felix/trunk/framework/src/main/java/org/apache/felix/framework/BundleImpl.java Thu Jul
26 16:18:02 2012
@@ -1161,23 +1161,14 @@ class BundleImpl implements Bundle, Bund
     {
         m_revisions.add(0, revision);
 
-        // Set protection domain after adding the revision to the bundle,
-        // since this requires that the bundle has a revision.
-        ((BundleRevisionImpl) revision).setProtectionDomain(
-            new BundleProtectionDomain(getFramework(), this));
-
-        SecurityProvider sp = getFramework().getSecurityProvider();
-        if ((sp != null) && (System.getSecurityManager() != null))
+        try
         {
-            try
-            {
-                sp.checkBundle(this);
-            }
-            catch (Exception ex)
-            {
-                m_revisions.remove(0);
-                throw ex;
-            }
+            getFramework().setBundleProtectionDomain(this, (BundleRevisionImpl) revision);
+        }
+        catch (Exception ex)
+        {
+            m_revisions.remove(0);
+            throw ex;
         }
 
         // TODO: REFACTOR - consider nulling capabilities for extension bundles

Modified: felix/trunk/framework/src/main/java/org/apache/felix/framework/BundleProtectionDomain.java
URL: http://svn.apache.org/viewvc/felix/trunk/framework/src/main/java/org/apache/felix/framework/BundleProtectionDomain.java?rev=1366063&r1=1366062&r2=1366063&view=diff
==============================================================================
--- felix/trunk/framework/src/main/java/org/apache/felix/framework/BundleProtectionDomain.java
(original)
+++ felix/trunk/framework/src/main/java/org/apache/felix/framework/BundleProtectionDomain.java
Thu Jul 26 16:18:02 2012
@@ -36,7 +36,7 @@ public class BundleProtectionDomain exte
     private final WeakReference m_revision;
 
     // TODO: SECURITY - This should probably take a revision, not a bundle.
-    BundleProtectionDomain(Felix felix, BundleImpl bundle)
+    BundleProtectionDomain(Felix felix, BundleImpl bundle, Object certificates)
         throws MalformedURLException
     {
         super(
@@ -46,7 +46,7 @@ public class BundleProtectionDomain exte
                     bundle._getLocation(),
                     new FakeURLStreamHandler()
                     ),
-                (Certificate[]) null),
+                (Certificate[]) certificates),
             null);
         m_felix = new WeakReference(felix);
         m_bundle = new WeakReference(bundle);

Modified: felix/trunk/framework/src/main/java/org/apache/felix/framework/Felix.java
URL: http://svn.apache.org/viewvc/felix/trunk/framework/src/main/java/org/apache/felix/framework/Felix.java?rev=1366063&r1=1366062&r2=1366063&view=diff
==============================================================================
--- felix/trunk/framework/src/main/java/org/apache/felix/framework/Felix.java (original)
+++ felix/trunk/framework/src/main/java/org/apache/felix/framework/Felix.java Thu Jul 26 16:18:02
2012
@@ -699,6 +699,10 @@ public class Felix extends BundleImpl im
                     archives = null;
                 }
 
+                // Create system bundle activator and bundle context so we can activate it.
+                setActivator(new SystemBundleActivator());
+                setBundleContext(new BundleContextImpl(m_logger, this, this));
+
                 // Now load all cached bundles.
                 for (int i = 0; (archives != null) && (i < archives.length); i++)
                 {
@@ -759,9 +763,6 @@ public class Felix extends BundleImpl im
                 // so create a gate for that purpose.
                 m_shutdownGate = new ThreadGate();
 
-                // Create system bundle activator and bundle context so we can activate it.
-                setActivator(new SystemBundleActivator());
-                setBundleContext(new BundleContextImpl(m_logger, this, this));
                 try
                 {
                     Felix.m_secureAction.startActivator(
@@ -778,6 +779,53 @@ public class Felix extends BundleImpl im
                 // its bundle context to the logger so that it can track log services.
                 m_logger.setSystemBundleContext(_getBundleContext());
 
+                // We have to check with the security provider (if there is one). 
+                // This is to avoid having bundles in the cache that have been tampered with
+                SecurityProvider sp = getFramework().getSecurityProvider();
+                if ((sp != null) && (System.getSecurityManager() != null))
+                {
+                    boolean locked = acquireGlobalLock();
+                    if (!locked)
+                    {
+                        throw new BundleException(
+                            "Unable to acquire the global lock to check the bundle.");
+                    }
+                    try
+                    {
+                        for (Object bundle : m_installedBundles[IDENTIFIER_MAP_IDX].values())
+                        {
+                            try
+                            {
+                                if (bundle != this)
+                                {
+                                    setBundleProtectionDomain((BundleImpl) bundle, (BundleRevisionImpl)
((BundleImpl) bundle).adapt(BundleRevisionImpl.class));
+                                }
+                            }
+                            catch (Exception ex)
+                            {
+                                ((BundleImpl) bundle).close();
+                                maps = new Map[] {
+                                    new HashMap<String, BundleImpl>(m_installedBundles[LOCATION_MAP_IDX]),
+                                    new TreeMap<Long, BundleImpl>(m_installedBundles[IDENTIFIER_MAP_IDX])
+                                };
+                                maps[LOCATION_MAP_IDX].remove(((BundleImpl) bundle)._getLocation());
+                                maps[IDENTIFIER_MAP_IDX].remove(new Long(((BundleImpl) bundle).getBundleId()));
+                                m_installedBundles = maps;
+
+                                m_logger.log(
+                                    Logger.LOG_ERROR,
+                                    "Bundle in cache doesn't pass security check anymore.",
+                                    ex);
+                            }
+                        }
+                    }
+                    finally
+                    {
+                        // Always release the global lock.
+                        releaseGlobalLock();
+                    }
+                }
+                
                 // Clear the cache of classes coming from the system bundle.
                 // This is only used for Felix.getBundle(Class clazz) to speed
                 // up class lookup for the system bundle.
@@ -793,6 +841,20 @@ public class Felix extends BundleImpl im
         }
     }
 
+    void setBundleProtectionDomain(BundleImpl bundleImpl, BundleRevisionImpl revisionImpl)
throws Exception
+    {
+        Object certificates = null;
+        SecurityProvider sp = getFramework().getSecurityProvider();
+        if ((sp != null) && (System.getSecurityManager() != null))
+        {
+            sp.checkBundle(bundleImpl);
+            Map signers = (Map) sp.getSignerMatcher(this, Bundle.SIGNERS_TRUSTED);
+            certificates = signers.keySet().toArray(new java.security.cert.Certificate[0]);
+        }
+        revisionImpl.setProtectionDomain(
+            new BundleProtectionDomain(this, bundleImpl, certificates));
+    }
+
     /**
      * This method starts the framework instance, which will transition the
      * framework from start level 0 to its active start level as specified in



Mime
View raw message