building secure osgi applications
DESCRIPTION
Modern applications and software solutions increasingly center around loosely coupled and extensible architectures. Component or Service orientation is applied in almost all areas of application development including distributed systems, ubiquitous computing, embedded systems, and client-side applications. The Java based OSGi framework specification lends itself well as a platform for loosely coupled and extensible applications and is rapidly gaining ground as the de-facto plugin solution for Java based applications. It allows for lightweight implementations that limit themselves to the CDC profile and are ideally suited as embedded plugin frameworks. One of the main drawbacks of dynamically extensible applications, however, are the potential security issues that arise due to executing untrusted code without appropriated safety-measures in place. Secure sandboxes and their restrictions are difficult to get right and often hard to deal with in the development of applications. The OSGi specifications have an extensive and very powerful security model that eases this difficult task. This presentation focuses on embedding various OSGi framework implementations namely, Eclipse Equinox and Apache Felix, into applications as a means of plugin mechanism while taking advantage of the often overlooked benefits of this solution: security.TRANSCRIPT
![Page 1: Building Secure OSGi Applications](https://reader034.vdocuments.mx/reader034/viewer/2022042614/5587411dd8b42ab35d8b4583/html5/thumbnails/1.jpg)
luminis
Building Secure OSGi ApplicationsKarl PaulsMarcel Offermans
![Page 2: Building Secure OSGi Applications](https://reader034.vdocuments.mx/reader034/viewer/2022042614/5587411dd8b42ab35d8b4583/html5/thumbnails/2.jpg)
luminis
Who are we?
• Karl Pauls
• Marcel Offermans
EnschedeArnhem
image © 2008 Google Earth
![Page 3: Building Secure OSGi Applications](https://reader034.vdocuments.mx/reader034/viewer/2022042614/5587411dd8b42ab35d8b4583/html5/thumbnails/3.jpg)
luminis
Agenda
• Introduction to OSGi layers and Security
• Java and OSGi Security
• Enabling Security in Equinox and Apache Felix
• PermissionAdmin and OSGi specific permissions
• ConditionalPermissionAdmin
• Signed Bundles and Local Permissions
• Custom and postponed conditions
![Page 4: Building Secure OSGi Applications](https://reader034.vdocuments.mx/reader034/viewer/2022042614/5587411dd8b42ab35d8b4583/html5/thumbnails/4.jpg)
luminis
Agenda
• Introduction to OSGi layers and Security
• Java and OSGi Security
• Enabling Security in Equinox and Apache Felix
• PermissionAdmin and OSGi specific permissions
• ConditionalPermissionAdmin
• Signed Bundles and Local Permissions
• Custom and postponed conditions
![Page 5: Building Secure OSGi Applications](https://reader034.vdocuments.mx/reader034/viewer/2022042614/5587411dd8b42ab35d8b4583/html5/thumbnails/5.jpg)
luminis
OSGi today
OSGi technology is the dynamic module system for Java™
OSGi technology is Universal Middleware.
OSGi technology provides a service-oriented, component-based environment for developers and offers standardized ways to manage the software lifecycle. These capabilities greatly increase the value of a wide range of computers and devices that use the Java™ platform.
![Page 6: Building Secure OSGi Applications](https://reader034.vdocuments.mx/reader034/viewer/2022042614/5587411dd8b42ab35d8b4583/html5/thumbnails/6.jpg)
luminis
OSGi Specification
OSGi Service PlatformService CompendiumThe OSGi Alliance
Release 4, Version 4.1April 2007
OSGi Alliance
Digitally signed by OSGi Alliance DN: cn=OSGi Alliance, c=US Date: 2007.02.22 14:44:10 + 01'00'
Signatu re Not Verified
OSGi Service PlatformCore SpecificationThe OSGi Alliance
Release 4, Version 4.1April 2007
OSGi Alliance
Digitally signed by OSGi Alliance DN: cn=OSGi Alliance, c=US Date: 2007.02.22 14:45:47 + 01'00'
Signatur e Not Verified
![Page 7: Building Secure OSGi Applications](https://reader034.vdocuments.mx/reader034/viewer/2022042614/5587411dd8b42ab35d8b4583/html5/thumbnails/7.jpg)
luminis
OSGi Framework Layering
SERVICE MODEL
MODULE
LIFECYCLE
ExecutionEnvironment
L3 - Provides a publish/find/bind service model to decouple bundles
L2 - Manages the life cycle of a bundle in a framework without requiring the vm to be restarted
L1 - Creates the concept of a module (aka. bundles) that use classes from each other in a controlled way according to system and bundle constraints
L0 - OSGi Minimum Execution EnvironmentCDC/FoundationJavaSE
![Page 8: Building Secure OSGi Applications](https://reader034.vdocuments.mx/reader034/viewer/2022042614/5587411dd8b42ab35d8b4583/html5/thumbnails/8.jpg)
luminis
Module Layer (1/3)
• Unit of deploymentis the bundle i.e., a JAR
• Separate class loaderper bundle
• Class loader graph
• Independent namespaces
• Class sharing at the Java package level
Module
ModuleBundle Bundle Bundle
org.apache.utils 1.0
org.apache.utils 1.1org.apache.log 2.3
org.apache.db 1.4
Bundle
exports
imports
exports
imports
exports
exports
![Page 9: Building Secure OSGi Applications](https://reader034.vdocuments.mx/reader034/viewer/2022042614/5587411dd8b42ab35d8b4583/html5/thumbnails/9.jpg)
luminis
Module Layer (2/3)
• Multi-version support
• i.e., side-by-side versions
• Explicit code boundaries and dependencies
• i.e., package imports and exports
• Support for various sharing policies
• i.e., arbitrary version range support
• Arbitrary export/import attributes
• Influence package selection Module
![Page 10: Building Secure OSGi Applications](https://reader034.vdocuments.mx/reader034/viewer/2022042614/5587411dd8b42ab35d8b4583/html5/thumbnails/10.jpg)
luminis
Module Layer (3/3)
• Sophisticated class space consistency model
• Ensures code constraints are not violated
• Package filtering for fine-grained class visibility
• Exporters may include/exclude specific classes from exported package
• Bundle fragments
• A single logical module in multiple physical bundles
• Bundle dependencies
• Allows for tight coupling when required Module
![Page 11: Building Secure OSGi Applications](https://reader034.vdocuments.mx/reader034/viewer/2022042614/5587411dd8b42ab35d8b4583/html5/thumbnails/11.jpg)
luminis
Life-cycle Layer
• Managed life cycle
• States for each bundle;
• Allows updates of existing bundles.
• Dynamically install, start, update, and uninstall
Life-cycle
Life-cycle
start
end
installedinstall
startingstart
stopping stop
activeresolved
uninstalled
uninstall
Module
![Page 12: Building Secure OSGi Applications](https://reader034.vdocuments.mx/reader034/viewer/2022042614/5587411dd8b42ab35d8b4583/html5/thumbnails/12.jpg)
luminis
Service Layer
• OSGi framework promotes service oriented interaction pattern among bundles
Service
Service
Log Database
Bundle Bundle Bundle
publish useuse
publish
Bundle
Prefs
publish
use
Service Provider
Service Requester
Service Registry
interact
publish find
Life-cycle
Module
![Page 13: Building Secure OSGi Applications](https://reader034.vdocuments.mx/reader034/viewer/2022042614/5587411dd8b42ab35d8b4583/html5/thumbnails/13.jpg)
luminis
Security
• Optional Security Layer based on Java permissions
• Infrastructure to define, deploy, and manage fine-grained application permissions
• Code authenticated by location or signer
• Well defined API to manage permissions
• PermissionAdmin
• ConditionalPermissionAdmin
Security
Module
Life-cycle
Service
![Page 14: Building Secure OSGi Applications](https://reader034.vdocuments.mx/reader034/viewer/2022042614/5587411dd8b42ab35d8b4583/html5/thumbnails/14.jpg)
luminis
Agenda
• Introduction to OSGi layers and Security
• Java and OSGi Security
• Enabling Security in Equinox and Apache Felix
• PermissionAdmin and OSGi specific permissions
• ConditionalPermissionAdmin
• Signed Bundles and Local Permissions
• Custom and postponed conditions
![Page 15: Building Secure OSGi Applications](https://reader034.vdocuments.mx/reader034/viewer/2022042614/5587411dd8b42ab35d8b4583/html5/thumbnails/15.jpg)
luminis
Security Concepts Overview
• OSGi uses codebased security following the Java Security Model
• Makes use of Protection Domain
• The stack walk based Permission Check
• Signed bundles
• User based security is supported by the UserAdmin service but not integrated in the standard permission check as with JAAS
• Additionally, PermissionAdmin and ConditionalPermissionAdmin provide sophisticated management infrastructure
![Page 16: Building Secure OSGi Applications](https://reader034.vdocuments.mx/reader034/viewer/2022042614/5587411dd8b42ab35d8b4583/html5/thumbnails/16.jpg)
luminis
Protection Domain
• Encapsulates characteristics of a domain
• One protection domain per bundle
• Encloses a set of classes whose instances are granted a set of permissions
• Set of permissions associated with each bundle
• Permission check consults all protection domains on the stack
![Page 17: Building Secure OSGi Applications](https://reader034.vdocuments.mx/reader034/viewer/2022042614/5587411dd8b42ab35d8b4583/html5/thumbnails/17.jpg)
luminis
Permission Check
• Invoked either by call to SecurityManager.check* or AccessController.checkPermission
• SecurityManager is old way to do it
• OSGi requires usage of the SecurityManager for full functionality
• Privileged calls used to cut off stack walk
• Disregard code on the stack earlier then the latest privileged call.
• Merges context of parent thread as well
![Page 18: Building Secure OSGi Applications](https://reader034.vdocuments.mx/reader034/viewer/2022042614/5587411dd8b42ab35d8b4583/html5/thumbnails/18.jpg)
luminis
Algorithm
AccessController.checkPermission(Permission p)
A.class
C.class
B.class
D.class
E.class
Protection Domain:Bundle A
Protection Domain:Bundle B
Privileged Call if (!(PermissionsA.implies(p) && PermissionsB.implies(p))
{throw new SecurityException();
}
PermissionsA
PermissionsB
![Page 19: Building Secure OSGi Applications](https://reader034.vdocuments.mx/reader034/viewer/2022042614/5587411dd8b42ab35d8b4583/html5/thumbnails/19.jpg)
luminis
Deployment Topology
• Management Agent, responsible for:
• life cycle management of the framework
• security
• Can use SynchronousBundleListener for on the fly configuration
OSGi framework
Provisioning Server
OBR managem
ent
agent
bundle
A
bundle
B
bundle
C
![Page 20: Building Secure OSGi Applications](https://reader034.vdocuments.mx/reader034/viewer/2022042614/5587411dd8b42ab35d8b4583/html5/thumbnails/20.jpg)
luminis
Agenda
• Introduction to OSGi layers and Security
• Java and OSGi Security
• Enabling Security in Equinox and Apache Felix
• PermissionAdmin and OSGi specific permissions
• ConditionalPermissionAdmin
• Signed Bundles and Local Permissions
• Custom and postponed conditions
![Page 21: Building Secure OSGi Applications](https://reader034.vdocuments.mx/reader034/viewer/2022042614/5587411dd8b42ab35d8b4583/html5/thumbnails/21.jpg)
luminis
Enable Security: Equinox
• Properties for security manager, keystore, signed bundles support
• -Djava.security.manager=""
• -Dosgi.framework.keystore=file:lib/keystore.ks
• -Dosgi.signedcontent.support=true
• Java Security Policy must give AllPermission
• -Djava.security.policy=all.policy
• grant { permission java.lang.AllPermission };
java -Djava.security.manager="" -Djava.security.policy=all.policy \ -Dosgi.framework.keystore=file:keystore.ks -Dosgi.signedcontent.support=true -jar org.eclipse.equinox.launcher.jar -noExit
![Page 22: Building Secure OSGi Applications](https://reader034.vdocuments.mx/reader034/viewer/2022042614/5587411dd8b42ab35d8b4583/html5/thumbnails/22.jpg)
luminis
Enable Security: Felix
• Felix security is still experimental
• Not all permission checks implemented
• Configuration and documentation needs improvements
• Properties for security manager, keystore, keystore password, keystore type
• Java Security Policy must give AllPermission
• -Djava.security.policy=all.policy
• grant { permission java.lang.AllPermission };
java -Djava.security.manager -Djava.security.policy=all.policy -Dfelix.keystore=keystore.ks -Dfelix.keystore.pass=luminis -jar felix.jar
![Page 23: Building Secure OSGi Applications](https://reader034.vdocuments.mx/reader034/viewer/2022042614/5587411dd8b42ab35d8b4583/html5/thumbnails/23.jpg)
luminis
Example - Running Secure
public class Activator implements BundleActivator { public void start(BundleContext context) throws Exception { // Check for a security manager SecurityManager sm = System.getSecurityManager(); if (sm == null) { throw new BundleException("No SecurityManager installed"); } // Check for AllPermission sm.checkPermission(new AllPermission()); }
public void stop(BundleContext context) throws Exception { }}
![Page 24: Building Secure OSGi Applications](https://reader034.vdocuments.mx/reader034/viewer/2022042614/5587411dd8b42ab35d8b4583/html5/thumbnails/24.jpg)
luminis
Agenda
• Introduction to OSGi layers and Security
• Java and OSGi Security
• Enabling Security in Equinox and Apache Felix
• PermissionAdmin and OSGi specific permissions
• ConditionalPermissionAdmin
• Signed Bundles and Local Permissions
• Custom and postponed conditions
![Page 25: Building Secure OSGi Applications](https://reader034.vdocuments.mx/reader034/viewer/2022042614/5587411dd8b42ab35d8b4583/html5/thumbnails/25.jpg)
luminis
Permission Admin (1/3)
• Old (pre 4.0) way of managing permissions
• Provides information about current permissions
• Allows a management agent to set permissions per bundle
• Permissions are based on bundle locations with a fallback to a set of default permissions
![Page 26: Building Secure OSGi Applications](https://reader034.vdocuments.mx/reader034/viewer/2022042614/5587411dd8b42ab35d8b4583/html5/thumbnails/26.jpg)
luminis
PermissionAdmin (2/3)Permission Admin service Permission Admin Service Specification Version 1.2
254-278 OSGi Service Platform Release 4
Figure 10.48 Class Diagram org.osgi.service.permissionadmin.
10.1.3 Operation
The Framework maintains a repository of permissions. These permissions
are stored under the bundle location string. Using the bundle location
allows the permissions to be set before a bundle is downloaded. The Frame-
work must consult this repository when it needs the permissions of a bun-
dle. When no specific permissions are set, the bundle must use the default
permissions. If no default is set, the bundle must use
java.security .Al lPermission . If the default permissions are changed, a bun-
dle with no specific permissions must immediately start using the new
default permissions.
The Permission Admin service is registered by the Framework’s system bun-
dle under the org.osg i.service .permiss ionadmin.PermissionAdmin inter-
face. This is an optional singleton service, so at most one Permission Admin
service is registered at any moment in time.
The Permission Admin service provides access to the permission repository.
A Management Agent can get, set, update, and delete permissions from this
repository. A Management Agent can also use a
SynchronousBundleListener object to set the permissions during the instal-
lation or updating of a bundle.
10.2 Permission Admin service
The Permission Admin service needs to manipulate the default permissions
and the permissions associated with a specific bundle. The default permis-
sions and the bundle-specific permissions are stored persistently. It is possi-
ble to set a bundle’s permissions before the bundle is installed in the
Framework because the bundle’s location is used to set the bundle’s permis-
sions.
The manipulation of a bundle’s permissions, however, may also be done in
real time when a bundle is downloaded or just before the bundle is down-
loaded. To support this flexibility, a SynchronousBundleListener object may
be used by a Management Agent to detect the installation or update of a
bundle, and set the required permissions before the installation completes.
Permissions are activated before the first time a permission check for a bun-
dle is performed. This means that if a bundle has opened a file, this file must
remain usable even if the permission to open that file is removed at a later
time.
<<interface>>PermissionAdmin
<<class>>PermissionInfo
0..n1
java.security.Permission
constructs
1
1
bundle location
![Page 27: Building Secure OSGi Applications](https://reader034.vdocuments.mx/reader034/viewer/2022042614/5587411dd8b42ab35d8b4583/html5/thumbnails/27.jpg)
luminis
PermissionAdmin (3/3)
• Relative FilePermissions are assumed to be relative to the bundle storage area
• All permission changes need AllPermission
• the first thing a management agent has to do is give itself AllPermission
• If ConditionalPermissionAdmin is present (as is the case in our environment) then default permissions are ignored unless the ConditionalPermissionAdmin has not been set-up with at least one entry
![Page 28: Building Secure OSGi Applications](https://reader034.vdocuments.mx/reader034/viewer/2022042614/5587411dd8b42ab35d8b4583/html5/thumbnails/28.jpg)
luminis
PermissionInfo
• Permission representation used
• Encapsulates three pieces of information
• type - class name of the permission
• name - name argument of the permission
• actions - actions argument of the permission
new PermissionInfo(AdminPermission.class.getName(), "(id=10)", AdminPermission.EXECUTE);
![Page 29: Building Secure OSGi Applications](https://reader034.vdocuments.mx/reader034/viewer/2022042614/5587411dd8b42ab35d8b4583/html5/thumbnails/29.jpg)
luminis
Example
PermissionAdmin admin = getPermissionAdmin();
admin.setPermissions(context.getBundle().getLocation(), new PermissionInfo[]{new PermissionInfo(
AllPermission.class.getName(), "", "")});
PermissionInfo[] previous = admin.getDefaultPermissions();
admin.setDefaultPermissions(new PermissionInfo[0]);
// unsetadmin.setDefaultPermissions(previous);
![Page 30: Building Secure OSGi Applications](https://reader034.vdocuments.mx/reader034/viewer/2022042614/5587411dd8b42ab35d8b4583/html5/thumbnails/30.jpg)
luminis
Agenda
• Introduction to OSGi layers and Security
• Java and OSGi Security
• Enabling Security in Equinox and Apache Felix
• PermissionAdmin and OSGi specific permissions
• ConditionalPermissionAdmin
• Signed Bundles and Local Permissions
• Custom and postponed conditions
![Page 31: Building Secure OSGi Applications](https://reader034.vdocuments.mx/reader034/viewer/2022042614/5587411dd8b42ab35d8b4583/html5/thumbnails/31.jpg)
luminis
OSGi specific permissions
• OSGi specifications define special permissions for framework and service related tasks
• The core framework specification defines:
• AdminPermission - for all framework specific actions
• PackagePermission - for package import and export
• ServicePermission - for service providing and usage
• BundlePermission - for extensions/fragments
• Custom permissions can be used if they have been exported by a bundle or the classpath
![Page 32: Building Secure OSGi Applications](https://reader034.vdocuments.mx/reader034/viewer/2022042614/5587411dd8b42ab35d8b4583/html5/thumbnails/32.jpg)
luminis
PackagePermission
• A bundle‘s authority to import/export a package
• Name is the package as dot-separated string
• Wildcards are supported
• Two actions: EXPORT and IMPORT.
• EXPORT implies IMPORT
Import-Package: net.luminis.pub.foo, net.luminis.barExport-Package: net.luminis.bar
new PackagePermission("net.luminis.pub.*", PackagePermission.IMPORT);new PackagePermission("net.luminis.bar", PackagePermission.EXPORT);
System.getSecurityManager().checkPermission( new PackagePermission("net.luminis.pub.foo", PackagePermission.IMPORT));System.getSecurityManager().checkPermission( new PackagePermission("net.luminis.bar", PackagePermission.EXPORT));
![Page 33: Building Secure OSGi Applications](https://reader034.vdocuments.mx/reader034/viewer/2022042614/5587411dd8b42ab35d8b4583/html5/thumbnails/33.jpg)
luminis
ServicePermission
• A bundle‘s authority to register/get a service
• Name is the name of the service interface as a dot separated string
• Wildcards may be used for the classname
• Two Actions: GET and REGISTER
new ServicePermission("net.luminis.pub.*", ServicePermission.GET);new ServicePermission("net.luminis.pub.Bar", ServicePermission.REGISTER);
context.getServiceReference("net.luminis.pub.Foo");context.registerService("net.luminis.pub.Bar", new Bar(), null);
System.getSecurityManager().checkPermission( new ServicePermission("net.luminis.pub.Foo", ServicePermission.GET));System.getSecurityManager().checkPermission( new ServicePermission("net.luminis.pub.Bar", ServicePermission.REGISTER));
![Page 34: Building Secure OSGi Applications](https://reader034.vdocuments.mx/reader034/viewer/2022042614/5587411dd8b42ab35d8b4583/html5/thumbnails/34.jpg)
luminis
BundlePermission
• A bundle‘s authority to require/provide/attach a bundle/fragment
• Name is the bundle symbolic name
• Wildcards may be used
• Four Actions: PROVIDE, REQUIRE, HOST, and FRAGMENT
• PROVIDE implies REQUIRE
![Page 35: Building Secure OSGi Applications](https://reader034.vdocuments.mx/reader034/viewer/2022042614/5587411dd8b42ab35d8b4583/html5/thumbnails/35.jpg)
luminis
AdminPermission (1/3)
• A bundle‘s authority to perform specific privileged administrative operations or get sensitive informations about a bundle.
• Name is a filter expression. The filter gives access to the following parameters:
• signer - A DN chain of bundle signers
• location - The location of a bundle
• id - The bundle ID of the bundle
• name - The symbolic name of a bundle
![Page 36: Building Secure OSGi Applications](https://reader034.vdocuments.mx/reader034/viewer/2022042614/5587411dd8b42ab35d8b4583/html5/thumbnails/36.jpg)
luminis
AdminPermission (2/3)
• There are eleven Actions:
• class - load a class from a bundle
• execute - start/stop bundle and set bundle startlevel
• extensionLifecycle - manage extension bundle
• lifecycle - manage bundle (update/uninstall/etc.)
• listener - add/remove synchronous bundle listeners
• metadata - get manifest and location
• resolve - refresh and resolve a bundle
• resource - get/find resources from a bundle
• startlevel - set startlevel and initial bundle startlevel
• context - get bundle context
![Page 37: Building Secure OSGi Applications](https://reader034.vdocuments.mx/reader034/viewer/2022042614/5587411dd8b42ab35d8b4583/html5/thumbnails/37.jpg)
luminis
AdminPermission (3/3)
context.installBundle("file:bundle.jar").start();
new AdminPermission( "(&(signer=o=luminis)(name=net.luminis.*)(location=file://*)(id>=10))", AdminPermission.LIFECYCLE + "," + AdminPermission.EXECUTE);
System.getSecurityManager().checkPermission(new AdminPermission(bundle));
![Page 38: Building Secure OSGi Applications](https://reader034.vdocuments.mx/reader034/viewer/2022042614/5587411dd8b42ab35d8b4583/html5/thumbnails/38.jpg)
luminis
Example - Configure Security
admin.setDefaultPermissions(new PermissionInfo[] {
new PermissionInfo(PackagePermission.class.getName(), "*", PackagePermission.IMPORT)
}); admin.setPermissions(context.getBundle(1).getLocation(),
new PermissionInfo[] {new PermissionInfo(AdminPermission.class.getName(), "*", "*"), new PermissionInfo(ServicePermission.class.getName(), "*",
ServicePermission.GET ), new PermissionInfo(ServicePermission.class.getName(), "org.apache.felix.shell.*",
ServicePermission.REGISTER), new PermissionInfo(PackagePermission.class.getName(), "org.apache.felix.shell",
PackagePermission.EXPORT), new PermissionInfo(PropertyPermission.class.getName(), "*", "read"), new PermissionInfo(NetPermission.class.getName(), "specifyStreamHandler", "")};
![Page 39: Building Secure OSGi Applications](https://reader034.vdocuments.mx/reader034/viewer/2022042614/5587411dd8b42ab35d8b4583/html5/thumbnails/39.jpg)
luminis
Agenda
• Introduction to OSGi layers and Security
• Java and OSGi Security
• Enabling Security in Equinox and Apache Felix
• PermissionAdmin and OSGi specific permissions
• ConditionalPermissionAdmin
• Signed Bundles and Local Permissions
• Custom and postponed conditions
![Page 40: Building Secure OSGi Applications](https://reader034.vdocuments.mx/reader034/viewer/2022042614/5587411dd8b42ab35d8b4583/html5/thumbnails/40.jpg)
luminis
Conditional Permission Admin
• New (4.0) way of doing permission management
• use this exclusively for new implementations
• interoperability when both PA and CPA are present
• IF all conditions of a set of conditions match THEN apply the supplied permissions
• More flexible, extensible model
• Conditions evaluation is highly optimized
![Page 41: Building Secure OSGi Applications](https://reader034.vdocuments.mx/reader034/viewer/2022042614/5587411dd8b42ab35d8b4583/html5/thumbnails/41.jpg)
luminis
CondPermAdmin (1/4)
OSGi Service Platform Release 4 217-278
Conditional Permission Admin Specification Version 1.0 Introduction
Figure 9.34 org.osgi.service.condpermadmin package
9.1.3 Synopsis
A Conditional Permission Admin service maintains a system wide table of
Condit ionalPermissionInfo objects, which are an encoded form of condi-
tions and permissions. A manager can enumerate, delete, and add new
tuples to this table.
When a bundle is created, it creates a single Bundle Protection Domain. This
protection domain calculates the system permissions for that bundle by
instantiating the conditions and permissions defined in the permission
table, potentially pruning any entries that can never apply to that bundle
and optimizing entries that always apply.
A bundle can have local permissions defined in a Bundle Permission
Resource. These are the actual permissions needed by this bundle to operate.
A bundle’s effective permissions are the intersection of the local permis-
sions and the system permissions. During the permission check of the Java
Security Manager, each Protection Domain is first checked for the local per-
missions, if this fails, the check fails.
Otherwise, the Bundle Protection Domains of the calling bundles are con-
sulted to see if they imply the requested permission. To imply the requested
permission, the Bundle Protection Domain must find a tuple in its permis-
sion table where all conditions are satisfied and where the tuple’s permis-
sions imply the requested permission. However, certain conditions must
<<interface>>Conditional Perm. Admin
selects by
<<interface>>Condition Info
<<interface>>Conditional Perm. Info
<<interface>>Condition
<<interface>>Permission Info
Conditional Permission Admin Impl.
Permission
Manager Impl.
BundleProtection Domain
<<class>>Bundle Loc. Condition
Protection Domain
a Bundle
<<class>>Bundle Signer. Condition
location
selects by
signer
*
1
1 *
*
*
User Condition Impl
administers
has
searches
has
encodes
encodes
![Page 42: Building Secure OSGi Applications](https://reader034.vdocuments.mx/reader034/viewer/2022042614/5587411dd8b42ab35d8b4583/html5/thumbnails/42.jpg)
luminis
Conditions
• Purpose is to decide if a permission set is applicable or not.
• Can be postponed or immutable
• allows optimized evaluations
• Custom conditions can be used for more advanced use-cases
![Page 43: Building Secure OSGi Applications](https://reader034.vdocuments.mx/reader034/viewer/2022042614/5587411dd8b42ab35d8b4583/html5/thumbnails/43.jpg)
luminis
BundleLocationCondition
• Condition to test if the location of a bundle matches a pattern.
• matching is done based on filter string matching rules
new ConditionInfo(BundleLocationCondition.class.getName(), new String[] {context.getBundle().getLocation()});
new ConditionInfo(BundleLocationCondition.class.getName(), new String[] {"*://www.luminis.nl/*"});
![Page 44: Building Secure OSGi Applications](https://reader034.vdocuments.mx/reader034/viewer/2022042614/5587411dd8b42ab35d8b4583/html5/thumbnails/44.jpg)
luminis
Example
ConditionalPermissionAdmin condPermAdmin = getConditionalPermissionAdmin();
condPermAdmin.addConditionalPermissionInfo( new ConditionInfo[] {
new ConditionInfo( BundleLocationCondition.class.getName(), new String[]{"*://www.luminis.nl/*"}) }, new PermissionInfo[] { new PermissionInfo( AdminPermission.class.getName(), "(!(id=" + context.getBundle().getBundleId() + "))", "*") });
![Page 45: Building Secure OSGi Applications](https://reader034.vdocuments.mx/reader034/viewer/2022042614/5587411dd8b42ab35d8b4583/html5/thumbnails/45.jpg)
luminis
Example - Use Conditions
condPermAdmin.addConditionalPermissionInfo(new ConditionInfo[]{new ConditionInfo(BundleLocationCondition.class.getName(), new String[]{context.getBundle().getLocation()})}, ALLPERMISSION_INFO);
condPermAdmin.addConditionalPermissionInfo(new ConditionInfo[] { // we use an empty condition set for default permissions}, new PermissionInfo[] {new PermissionInfo(PackagePermission.class.getName(), "*",PackagePermission.IMPORT)
});
![Page 46: Building Secure OSGi Applications](https://reader034.vdocuments.mx/reader034/viewer/2022042614/5587411dd8b42ab35d8b4583/html5/thumbnails/46.jpg)
luminis
Agenda
• Introduction to OSGi layers and Security
• Java and OSGi Security
• Enabling Security in Equinox and Apache Felix
• PermissionAdmin and OSGi specific permissions
• ConditionalPermissionAdmin
• Signed Bundles and Local Permissions
• Custom and postponed conditions
![Page 47: Building Secure OSGi Applications](https://reader034.vdocuments.mx/reader034/viewer/2022042614/5587411dd8b42ab35d8b4583/html5/thumbnails/47.jpg)
luminis
Signed Bundles
• Authenticates the signer
• Ensures that the content has not been modified
• Bundle (jar) can be signed by multiple signers
• Basically, normal java jar signing with a few extras
• All entries must be signed except META-INF
• certificate chains represented as ; separated lists
• matching done using * and - wildcardscn=marrs,o=iQ,c=NL;cn=hans,o=luminis,c=NL
cn=marrs,o=IQ*;cn=*,o=luminis
cn=marrs;-;cn=*,o=luminis
![Page 48: Building Secure OSGi Applications](https://reader034.vdocuments.mx/reader034/viewer/2022042614/5587411dd8b42ab35d8b4583/html5/thumbnails/48.jpg)
luminis
Signing bundles in Eclipse
![Page 49: Building Secure OSGi Applications](https://reader034.vdocuments.mx/reader034/viewer/2022042614/5587411dd8b42ab35d8b4583/html5/thumbnails/49.jpg)
luminis
Signing bundles manually
<macrodef name="sign-bundle"> <attribute name="name" /> <attribute name="location" default="deploy/@{name}.jar" /> <sequential> <exec executable="jarsigner"> <arg line="-keystore file:lib/keystore.ks" /> <arg line="-storepass luminis" /> <arg line="@{location}" /> <arg line="luminis" /> </exec> </sequential> </macrodef>
jarsigner -keystore file:lib/keystore.ks \-storepass luminis bundle.jar luminis
![Page 50: Building Secure OSGi Applications](https://reader034.vdocuments.mx/reader034/viewer/2022042614/5587411dd8b42ab35d8b4583/html5/thumbnails/50.jpg)
luminis
Certificates and Keystores
keytool -genkey -keystore keystore.ks -alias marrs -storepass luminis \ -keypass luminis -dname "CN=Marcel, OU=iQ, O=luminis, L=Arnhem, C=NL"
keytool -selfcert -keystore keystore.ks -alias marrs -storepass luminis \ -keypass luminis -dname "CN=Marcel, OU=iQ, O=luminis, L=Arnhem, C=NL"
keytool -export -v -keystore keystore.ks -alias marrs -file luminis.cert \ -storepass luminis -keypass luminis
keytool -import -v -keystore keystore.ks -alias luminis -file luminis.cert \ -storepass luminis -keypass luminis
keytool -list -keystore keystore.ks -storepass luminis
marrs, Mar 13, 2008, keyEntry,luminis, Mar 13, 2008, trustedCertEntry
![Page 51: Building Secure OSGi Applications](https://reader034.vdocuments.mx/reader034/viewer/2022042614/5587411dd8b42ab35d8b4583/html5/thumbnails/51.jpg)
luminis
BundleSignerCondition
• Condition to test if the signer of a bundle matches a pattern
• Uses the wildcard matching
new ConditionInfo(BundleSignerCondition.class.getName(), new String[]{"*,o=luminis"})
![Page 52: Building Secure OSGi Applications](https://reader034.vdocuments.mx/reader034/viewer/2022042614/5587411dd8b42ab35d8b4583/html5/thumbnails/52.jpg)
luminis
Agenda
• Introduction to OSGi layers and Security
• Java and OSGi Security
• Enabling Security in Equinox and Apache Felix
• PermissionAdmin and OSGi specific permissions
• ConditionalPermissionAdmin
• Signed Bundles and Local Permissions
• Custom and postponed conditions
![Page 53: Building Secure OSGi Applications](https://reader034.vdocuments.mx/reader034/viewer/2022042614/5587411dd8b42ab35d8b4583/html5/thumbnails/53.jpg)
luminis
Local Permissions
• Defined in a resource inside the bundle
• Defines a set of permissions that are enforced by the framework
• A bundle can get less than these permissions, but never more
• Defaults to All Permissions
• Good way for operators to “audit” the permissions of a bundle
![Page 54: Building Secure OSGi Applications](https://reader034.vdocuments.mx/reader034/viewer/2022042614/5587411dd8b42ab35d8b4583/html5/thumbnails/54.jpg)
luminis
LocalPermissions
• OSGI-INF/permissions.perm
# Friday, Feb 24 2005 # ACME, chess game ( ..ServicePermission "..log.LogService" "GET" ) ( ..PackagePermission "..log" "IMPORT" ) ( ..ServicePermission "..cm.ManagedService" "REGISTER" )( ..PackagePermission "..cm" "IMPORT" ) ( ..ServicePermission "..useradmin.UserAdmin" "GET" ) ( ..PackagePermission "..cm" "SET" ) ( ..PackagePermission "com.acme.chess" "IMPORT,EXPORT" ) ( ..PackagePermission "com.acme.score" "IMPORT" )
![Page 55: Building Secure OSGi Applications](https://reader034.vdocuments.mx/reader034/viewer/2022042614/5587411dd8b42ab35d8b4583/html5/thumbnails/55.jpg)
luminis
Tip: local permissions tracing with Apache Felix
import java.security.Permission;
public class SecMan extends SecurityManager { public void checkPermission(Permission perm, Object context) { System.out.println(perm); try { super.checkPermission(perm, context); } catch (Exception ex) { ex.printStackTrace(); } }
public void checkPermission(Permission perm) { System.out.println(perm); try { super.checkPermission(perm); } catch (Exception ex) { ex.printStackTrace(); } }}
java -Djava.security.manager=SecMan -Djava.security.policy=all.policy \ -cp .:felix.jar org.apache.felix.main.Main
![Page 56: Building Secure OSGi Applications](https://reader034.vdocuments.mx/reader034/viewer/2022042614/5587411dd8b42ab35d8b4583/html5/thumbnails/56.jpg)
luminis
Example - Signed bundles
condPermAdmin.addConditionalPermissionInfo(new ConditionInfo[]{ new ConditionInfo(BundleSignerCondition.class.getName(),
new String[]{"*,o=luminis"}) }, ALLPERMISSION_INFO);
# Friday, Feb 24 2005 # task4.test, local ( org.osgi.framework.PackagePermission "org.osgi.framework" "IMPORT" ) ( java.io.FilePermission "/" "read,write" )
![Page 57: Building Secure OSGi Applications](https://reader034.vdocuments.mx/reader034/viewer/2022042614/5587411dd8b42ab35d8b4583/html5/thumbnails/57.jpg)
luminis
Agenda
• Introduction to OSGi layers and Security
• Java and OSGi Security
• Enabling Security in Equinox and Apache Felix
• PermissionAdmin and OSGi specific permissions
• ConditionalPermissionAdmin
• Signed Bundles and Local Permissions
• Custom and postponed conditions
![Page 58: Building Secure OSGi Applications](https://reader034.vdocuments.mx/reader034/viewer/2022042614/5587411dd8b42ab35d8b4583/html5/thumbnails/58.jpg)
luminis
Custom Condition
• Conditions must come from the classpath/system bundle
• Are constructed from ConditionInfo objects
• static getCondition(Bundle,ConditionInfo) method
• constructor with (Bundle, ConditionInfo) signature
class BeforeDateCondition implements Condition { private final long m_date; public static Condition getCondition(Bundle bundle,
ConditionInfo info) { return new BeforeDateCondition(bundle, info); } public BeforeDateCondition(Bundle bundle,
ConditionInfo info) { m_date = Long.parseLong(info.getArgs()[0]); } public boolean isMutable() { return m_date > System.currentTimeMillis(); }
public boolean isPostponed() { return false; }
public boolean isSatisfied() { return System.currentTimeMillis() < m_date; }
public boolean isSatisfied(Condition[] conditions, Dictionary context) {
return false; }}
![Page 59: Building Secure OSGi Applications](https://reader034.vdocuments.mx/reader034/viewer/2022042614/5587411dd8b42ab35d8b4583/html5/thumbnails/59.jpg)
luminis
Extension Bundles
• Extension bundles can deliver optional parts of the Framework implementation
• Necessary to add custom conditions because they have to come from the classpath
• No Import-Package, Require-Bundle, Bundle-NativeCode, DynamicImport-Package, or Bundle-Activator allowed
Fragment-Host: system.bundle; extension:=framework
![Page 60: Building Secure OSGi Applications](https://reader034.vdocuments.mx/reader034/viewer/2022042614/5587411dd8b42ab35d8b4583/html5/thumbnails/60.jpg)
luminis
Agenda
• Introduction to OSGi layers and Security
• Java and OSGi Security
• Enabling Security in Equinox and Apache Felix
• PermissionAdmin and OSGi specific permissions
• ConditionalPermissionAdmin
• Signed Bundles and Local Permissions
• Custom and postponed conditions
![Page 61: Building Secure OSGi Applications](https://reader034.vdocuments.mx/reader034/viewer/2022042614/5587411dd8b42ab35d8b4583/html5/thumbnails/61.jpg)
luminis
Postponed Conditions
• Optimize condition evaluation on multiple evaluations during the same permission check
• context map can be used to pass settings during evaluation
• Use if evaluation is expensive
public boolean isPostponed() { return true;}
public boolean isSatisfied(Condition[] conditions, Dictionary context) { // do evaluation for all conditions involved }
![Page 62: Building Secure OSGi Applications](https://reader034.vdocuments.mx/reader034/viewer/2022042614/5587411dd8b42ab35d8b4583/html5/thumbnails/62.jpg)
luminis
Example - Custom Postponed
condPermAdmin.addConditionalPermissionInfo(new ConditionInfo[]{ new ConditionInfo(AskUserCondition.class.getName(), new String[]{""})}, ALLPERMISSION_INFO);
public boolean isSatisfied(Condition[] conditions, Dictionary context) { StringBuilder buffer = new StringBuilder("Do you grant bundles: "); for (Condition condition : conditions) { buffer.append(
(AskUserCondition) condition).bundle.getBundleId()).append(" "); } buffer.append("AllPermission?"); return ask(buffer.toString());}
![Page 63: Building Secure OSGi Applications](https://reader034.vdocuments.mx/reader034/viewer/2022042614/5587411dd8b42ab35d8b4583/html5/thumbnails/63.jpg)
luminis
Demo
• Shows a custom condition that:
• is postponed, because it’s “expensive”
• asks the user for permission
![Page 64: Building Secure OSGi Applications](https://reader034.vdocuments.mx/reader034/viewer/2022042614/5587411dd8b42ab35d8b4583/html5/thumbnails/64.jpg)
luminis
Discussion
• We’ve showed:
• how security is integrated into OSGi
• the relation between Java 2 Security and OSGi
• how to use both Permission Admin and Conditional Permission admin
• how to use signed bundles, local permissions, and add custom permissions and conditions at runtime
![Page 65: Building Secure OSGi Applications](https://reader034.vdocuments.mx/reader034/viewer/2022042614/5587411dd8b42ab35d8b4583/html5/thumbnails/65.jpg)
luminis
Links
• Apache Felix and OSGi:http://felix.apache.org/http://www.osgi.org/
• Sample code:http://opensource.luminis.net/
• Karl Pauls: [email protected]
Marcel Offermans: [email protected]
![Page 66: Building Secure OSGi Applications](https://reader034.vdocuments.mx/reader034/viewer/2022042614/5587411dd8b42ab35d8b4583/html5/thumbnails/66.jpg)
luminis
Questions?!
? & !