Toaster example

Download the toaster example here. The following files are included in this zip-file:

Introduction

We define and implement a toaster library component which offers toasting services to clients. The library component shields its (sensitive) operations from being used by untrusted code by means of calls to ToasterPermissions.

This example is based on an example described in .NET Framework Security.

IPermission

New permission types can be defined by creating a new class that implements the interface IPermission. More specifically, the subclass should implement (and specify) three methods: IsSubsetOf, Intersect and Union.
Run compileipermission.bat to compile this interface to a dll.

ToasterPermission

We define a new permission type: ToasterPermission. ToasterPermissions have three parameters: All these parameters can be set when constructing a ToasterPermission and are immutable from then on.

Note that all ToasterPermission methods are marked as Pure, meaning that these methods are side-effect free and can hence be used in specifications. Our definition of side-effect free differs slightly from the one used in Spec#, as we allow object creation in a pure context.

Run compiletoasterpermission.bat to compile this class to a dll.

PermissionSet

A PermissionSet object is a set of permissions, that can contain at most one object of each permission type. PermissionSet provides a number of (pure) methods: Run compilepermissionset.bat to compile this class to a dll. Notice that both IPermission and PermissionSet are part of a built-in library and must not be provided or compiled by developers. In the .NET framework they are part of the Base Class Library.

Due to some limitations in the current version of Spec#, we introduced some pecularities in our code:

Library Component: Toaster

We define a library component whose source-code can be found in Toaster.ssc. This library offers toasting services to clients, but guards these sensitive services by access control checks (Demands). For example, the body of ContainsBread is guarded by the invocation of Demand on a ToasterPermission. Callers who lack the required permissions are not able to access the sensitive services.

The library component has a component-level contract and a number of method level-contracts. The component-level contracts declares that the component must receive at least ToasterPermission (with the right to get information and the right to eject bread with level less than or equal to 5) in order to run properly. The method level contracts specify what permissions are required by callers of the toaster component.

To verify the correctness of the library component versus its specification, we must apply the following steps:
  1. We first apply a Security-passing style transformation. The result of applying this transformation to Toaster.ssc is ToasterSPS.ssc.
  2. We then generate the BoogiePl-code for the transformed component using generatetoasterbpl.bat. A new file ToasterSPS.bpl should have been created.
  3. We introduce a number of axioms and functions in ToasterSPS.bpl: The result is ToasterSPS_mod.bpl.
  4. We can now perform the actual verification by calling verifytoaster.bat. Verification of the library component will succeed.

last update: November 1th 2005
email