Formal specification of Gemplus’ electronic purse case study Néstor Cataño & Marieke Huisman INRIA Sophia-Antipolis {ncatano,

Slides:



Advertisements
Similar presentations
Advanced programming tools at Microsoft
Advertisements

Joint work with Mike Barnett, Robert DeLine, Manuel Fahndrich, and Wolfram Schulte Verifying invariants in object-oriented programs K. Rustan M. Leino.
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 18 Program Correctness To treat programming.
Technologies for finding errors in object-oriented software K. Rustan M. Leino Microsoft Research, Redmond, WA Lecture 0 Summer school on Formal Models.
Automated Theorem Proving Lecture 1. Program verification is undecidable! Given program P and specification S, does P satisfy S?
Challenges in increasing tool support for programming K. Rustan M. Leino Microsoft Research, Redmond, WA, USA 23 Sep 2004 ICTAC Guiyang, Guizhou, PRC joint.
Rigorous Software Development CSCI-GA Instructor: Thomas Wies Spring 2012 Lecture 8.
Semantics Static semantics Dynamic semantics attribute grammars
The Java Modeling Language JML Erik Poll Digital Security Radboud University Nijmegen.
JML and ESC/Java2: An Introduction Karl Meinke School of Computer Science and Communication, KTH.
Securing Java applets Erik Poll Security of Systems (SOS) group University of Nijmegen
Presented by David LESENS and Johannes KANIG Thursday, 16 May 2013 Astrium Space Transportation AdaCore Formal Validation of Aerospace Software DASIA 2013.
Dept. of Computer Science A Runtime Assertion Checker for the Java Modeling Language (JML) Yoonsik Cheon and Gary T. Leavens SERP 2002, June 24-27, 2002.
Formal Methods of Systems Specification Logical Specification of Hard- and Software Prof. Dr. Holger Schlingloff Institut für Informatik der Humboldt.
An overview of JML tools and applications Lilian Burdy Gemplus Yoonsik Cheon, Gary Leavens Iowa Univ. David Cok Kodak Michael Ernst MIT Rustan Leino Microsoft.
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 18 Program Correctness To treat programming.
1 Chapter 4 Language Fundamentals. 2 Identifiers Program parts such as packages, classes, and class members have names, which are formally known as identifiers.
Software Testing and Quality Assurance
Static and Dynamic Contract Verifiers For Java Hongming Liu.
Houdini: An Annotation Assistant for ESC/Java Cormac Flanagan and K. Rustan M. Leino Compaq Systems Research Center.
OOP #10: Correctness Fritz Henglein. Wrap-up: Types A type is a collection of objects with common behavior (operations and properties). (Abstract) types.
From last time S1: l := new Cons p := l S2: t := new Cons *p := t p := t l p S1 l p tS2 l p S1 t S2 l t S1 p S2 l t S1 p S2 l t S1 p L2 l t S1 p S2 l t.
Software Quality: Testing and Verification II. 2 1.A failure is an unacceptable behaviour exhibited by a system — The frequency of failures measures software.
Chapter 1 Principles of Programming and Software Engineering.
CS 330 Programming Languages 09 / 16 / 2008 Instructor: Michael Eckmann.
Describing Syntax and Semantics
1 ES 314 Advanced Programming Lec 2 Sept 3 Goals: Complete the discussion of problem Review of C++ Object-oriented design Arrays and pointers.
Using data groups to specify and check side effects K. Rustan M. Leino Microsoft Research Arnd Poetzsch-Heffter Universität Kaiserslautern Yunhong Zhou.
© 2006 Pearson Addison-Wesley. All rights reserved2-1 Chapter 2 Principles of Programming & Software Engineering.
Jonathan Kuhn Robin Mange EPFL-SSC Compaq Systems Research Center Flanagan, Leino, Lillibridge, Nelson, Saxe and Stata.
Cs205: engineering software university of virginia fall 2006 Semantics and Specifying Procedures David Evans
Component-Based Software Engineering Components and Interfaces Paul Krause.
Ranga Rodrigo. Class is central to object oriented programming.
Language Evaluation Criteria
Software Engineering Prof. Dr. Bertrand Meyer March 2007 – June 2007 Chair of Software Engineering Static program checking and verification Slides: Based.
Mathematical Modeling and Formal Specification Languages CIS 376 Bruce R. Maxim UM-Dearborn.
Design by Contract in Java Concept and Comparison.
SWE 619 © Paul Ammann Procedural Abstraction and Design by Contract Paul Ammann Information & Software Engineering SWE 619 Software Construction cs.gmu.edu/~pammann/
Extended Static Checking for Java  ESC/Java finds common errors in Java programs: null dereferences, array index bounds errors, type cast errors, race.
ISBN Chapter 3 Describing Semantics -Attribute Grammars -Dynamic Semantics.
Formal Verification Lecture 9. Formal Verification Formal verification relies on Descriptions of the properties or requirements Descriptions of systems.
Today’s Agenda  Quick Review  Continue on JML Formal Methods in Software Engineering1.
CIS 771: Software Specifications Lecture 18: Specifying and Checking Partial Properties of Java Code Copyright , Matt Dwyer, John Hatcliff, and.
CS Data Structures I Chapter 2 Principles of Programming & Software Engineering.
High Integrity Ada in a UML and C world Peter Amey, Neil White Presented by Liping Cai.
Topic 1 Object Oriented Programming. 1-2 Objectives To review the concepts and terminology of object-oriented programming To discuss some features of.
Chapter 3 Part II Describing Syntax and Semantics.
Semantics In Text: Chapter 3.
1 CSCD 326 Data Structures I Software Design. 2 The Software Life Cycle 1. Specification 2. Design 3. Risk Analysis 4. Verification 5. Coding 6. Testing.
Spec# Andreas Vida. Motivation Correct and maintainable software Correct and maintainable software Cost effective software production Cost effective software.
Extended Static Checking for Java Cormac Flanagan Joint work with: Rustan Leino, Mark Lillibridge, Greg Nelson, Jim Saxe, and Raymie Stata.
Verificare şi Validarea Sistemelor Soft Tem ă Laborator 1 ESC/Java2 Extended Static Checker for Java Dat ă primire laborator: Lab 1 Dat ă predare laborator:
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
ANU COMP2110 Software Design in 2003 Lecture 10Slide 1 COMP2110 Software Design in 2004 Lecture 12 Documenting Detailed Design How to write down detailed.
L13: Design by Contract Definition Reliability Correctness Pre- and post-condition Asserts and Exceptions Weak & Strong Conditions Class invariants Conditions.
SWE 4743 Abstract Data Types Richard Gesick. SWE Abstract Data Types Object-oriented design is based on the theory of abstract data types Domain.
PROGRAMMING PRE- AND POSTCONDITIONS, INVARIANTS AND METHOD CONTRACTS B MODULE 2: SOFTWARE SYSTEMS 13 NOVEMBER 2013.
Institute for Applied Information Processing and Communications (IAIK) – Secure & Correct Systems 1 Static Checking  note for.
Extended Static Checking for Java Cormac Flanagan Joint work with: Rustan Leino, Mark Lillibridge, Greg Nelson, Jim Saxe, and Raymie Stata Compaq Systems.
Combining Static and Dynamic Reasoning for Bug Detection Yannis Smaragdakis and Christoph Csallner Elnatan Reisner – April 17, 2008.
Faithful mapping of model classes to mathematical structures Ádám Darvas ETH Zürich Switzerland Peter Müller Microsoft Research Redmond, WA, USA SAVCBS.
DBC NOTES. Design By Contract l A contract carries mutual obligations and benefits. l The client should only call a routine when the routine’s pre-condition.
Design by Contract. The Goal Ensure the correctness of our software (correctness) Recover when it is not correct anyway (robustness) Correctness: Assertions.
EECE 310: Software Engineering
Chapter 6 CS 3370 – C++ Functions.
Testing and Debugging.
Accessible Formal Methods A Study of the Java Modeling Language
Hoare-style program verification
Java Modeling Language (JML)
Programming Languages 2nd edition Tucker and Noonan
Presentation transcript:

Formal specification of Gemplus’ electronic purse case study Néstor Cataño & Marieke Huisman INRIA Sophia-Antipolis {ncatano,

The electronic purse Developed by trainee at Gemplus Goal: develop more complex application, using object-oriented features Revision by members research lab and new trainee Result: not completely finished, not fully representative

Software documentation Management & history of the development Clear, concise and unambiguous Correspondance with implementation

Some Fragments from LoyaltiesTable // huge modifications on 31/07/2000 // now, we handle AID objects instead of byte arrays that represents them. // that way, we gain some space, and code is clearer. /* the purse stores in this object the loyalties that are allowed to communicate with it*/ class LoyaltiesTable { //////////////// ATTRIBUTES //////////////// // temporarily modified by RM on 26/07/2000 for memory reason //private final static byte NB_MAX = (byte)20; private final static byte NB_MAX = (byte)3; … /* suppress all the entries of the loyalty specified by aid */ void delLoyalty(AID aid) {…} … /* suppress the notification of the loyalty specified by aid*/ void removeNotification(AID aid) {…}

Software documentation Management & history of the development Clear, concise and unambiguous Correspondance with implementation Formal specification And verification Difficult and labour-intensive

This talk Different approaches to formal specification and verification Static checking (lightweight formal methods) The electronic purse case study Static checking of the electronic purse: class invariants

Specification language Close to programming language Expressions from programming language Eiffel, JML, ESC/Java, Jass with specification-specific constructs (forall, exists, implication etc.)

Checking techniques Run-time checking Full verification (syntactic or semantic) (Eiffel, JML, Jass) (Jive) (LOOP) Static checking (ESC/Java)

Static checking with ESC/Java Compaq Research (Leino et al.) Focus on finding common program errors (nullpointers, array index out of bounds) Proof obligations to dedicated theorem prover (assume - assert pairs) Issues warnings

Static checking with ESC/Java ESC/Java = Compromise between soundness, completeness, and efficiency

ESC/Java pragmas Preconditions (requires) Postconditions (ensures) Exceptional postconditions (exsures) Modifies clause Class invariants Implication, quantification Value expression in pre-state (\old(E)) Result value of method (\result)

The electronic purse Supports debit, credit and currency change operations Interaction with loyalty, card issuer and terminal Packages: utils, pacapinterfaces and purse

The purse package PurseApplet: installation, (de)selection, communication with terminal Purse: –implements basic functionalities –keeps track of balance, transactions, currency changes, loyalties

The purse package AccessControl: restricted set of users for certain operations Currencies Cryptographic concepts

Writing the specification For each method: requires, ensures, exsures, modifies First basic classes (utils), then more application-specific Appropriate class invariants, e.g. restricting domain of instance variables

Writing the specification Discrepancies between documentation and implementation

Writing the specification Discrepancies between documentation and implementation

Writing the specification Discrepancies between documentation and implementation Usage of existing API specification

Writing the specification Discrepancies between documentation and implementation Usage of existing API specification.spec files for e.g. visa and crypto classes

Writing the specification Discrepancies between documentation and implementation Usage of existing API specification.spec files for e.g. visa and crypto classes Avoid warnings as much as possible, but still full specification

Class invariants Restrict state space of a class –reference never null pointer invariant purse != null; –variable within a certain range invariant decPart >= 0 && decPart < PRECISION; invariant intPart >= 0 && intPart < MAX_DECIMAL_NUMBER; */ Easy to write, easy to check

Enumeration types /* the transaction status*/ public static final byte INDETERMINE= (byte)0;... /* the transaction status*/ public static final byte TYPE_CREDIT= (byte)50; /* the transaction status*/ public static final byte TYPE_DEBIT= (byte)51;... /* the transaction type: debit or credit*/ private byte type;... /* set all this transaction attributes to 0*/void reset() { isValid = false; number = (short)0; type = INDETERMINE; typeProduit = (short)0;... }

/* the transaction type: debit or credit*/ private byte type;... /* set all this transaction attributes to 0*/ void reset() { isValid = false; number = (short)0; type = INDETERMINE; typeProduit = (short)0;... }

public AccessCondition() { super(); // commented by Rodolphe Muller on 16/06/2000 // strange to set the condition here to 0 and to // FREE above setCondition((byte)0); } Enumeration types invariant condition == FREE || condition == LOCKED || condition == SECRET_CODE || condition == SECURE_MESSAGING || condition == (SECRET_CODE | SECURE_MESSAGING) */ public AccessCondition() { super(); // commented by Rodolphe Muller on 16/06/2000 // strange to set the condition here to 0 and to // FREE above setCondition((byte)0); } public AccessCondition() { super(); // commented by Rodolphe Muller on 16/06/2000 // strange to set the condition here to 0 and to // FREE above setCondition((byte)0); } NB. FREE == (byte)1;

switch(condition) { case FREE:... case SECRET_CODE:... case SECURE_MESSAGING:... case SECRET_CODE | SECURE_MESSAGING:... case LOCKED:... default: assert false; t = AccessConditionException.C_C_INVALIDE; AccessConditionException.throwIt(t); } Avoiding dead code switch(condition) { case FREE:... case SECRET_CODE:... case SECURE_MESSAGING:... case SECRET_CODE | SECURE_MESSAGING:... case LOCKED:... default: t = AccessConditionException.C_C_INVALIDE; AccessConditionException.throwIt(t); }

Other problems Incorrect coding Forgetting variable modifiers (final) Underspecified documentation Is MAX_DECIMAL_NUMBER.999 legal? And how do you round it? Superfluous methods (isNegatif()) Complex and undocumented datastructures (with incorrect corrections)

Complete specification Available from verificard/electronic_purse

Conclusions Using lightweight formal methods, applications can be improved Class invariants make implicit assumptions explicit and check them Case study convinced Gemplus to look at JML and ESC/Java ESC/Java useful, but possibilities for improvement

Complete specification Available from verificard/electronic_purse

Writing the specification modifies M; requires true; ensures Q; exsures (E) !P; */ void m () {... }

Writing the specification Offensive modifies M; requires P; ensures Q; exsures (E) false; */ void m () {... } Defensive modifies M; requires true; ensures Q; exsures (E) !P; */ void m () {... }

Experiences with ESC/Java Pleasant tool, easy to work with Specifications written by non- experienced user Two/three months work all together

Suggestions for ESC/Java specification language Richer specification language modifies \nothing, modifies \field_of(E) Extra quantifiers Run-time exceptions without explicit throws clause Use of pure methods in specifications

modifies sessionNumber, date.jour, date.mois, date.annee, heure.heure, heure.minute; modifies ancienneDevise, nouvelleDevise, isValid, status; modifies id[*], terminalTC[*], terminalSN[*] ; requires es != null ; requires es.id != terminalTC & es.id != terminalSN & es.terminalTC != terminalSN; ensures sessionNumber == es.sessionNumber ; ensures ancienneDevise == es.ancienneDevise ; ensures nouvelleDevise == es.nouvelleDevise ; ensures isValid == es.isValid ; ensures status == es.status ; ensures (\forall int i;0 es.id[i] == id[i]); ensures (\forall int i;0 es.terminalTC[i] == terminalTC[i]); ensures (\forall int i;0 es.terminalSN[i] == terminalSN[i]); exsures (TransactionException e) e._reason == TransactionException.BUFFER_FULL && JCSystem._transactionDepth == 1; exsures (NullPointerException) false; exsures (ArrayIndexOutOfBoundsException) false; modifies sessionNumber, date.jour, date.mois, date.annee, heure.heure, heure.minute; modifies ancienneDevise, nouvelleDevise, isValid, status; modifies id[*], terminalTC[*], terminalSN[*] ; requires es != null ; requires es.id != terminalTC & es.id != terminalSN & es.terminalTC != terminalSN; ensures sessionNumber == es.sessionNumber ; ensures ancienneDevise == es.ancienneDevise ; ensures nouvelleDevise == es.nouvelleDevise ; ensures isValid == es.isValid ; ensures status == es.status ; ensures (\forall int i;0 es.id[i] == id[i]); ensures (\forall int i;0 es.terminalTC[i] == terminalTC[i]); ensures (\forall int i;0 es.terminalSN[i] == terminalSN[i]); exsures (TransactionException e) e._reason == TransactionException.BUFFER_FULL && JCSystem._transactionDepth == 1; exsures (NullPointerException) false; exsures (ArrayIndexOutOfBoundsException) false; Example specification

And as we would like it to be... modifies sessionNumber, date.jour, date.mois, date.annee, heure.heure, heure.minute; modifies ancienneDevise, nouvelleDevise, isValid, status; modifies id[*], terminalTC[*], terminalSN[*] ; requires es != null ; requires es.id != terminalTC & es.id != terminalSN & es.terminalTC != terminalSN; ensures this.equal(es); exsures (TransactionException e) e._reason == TransactionException.BUFFER_FULL && JCSystem._transactionDepth == 1; exsures (NullPointerException) false; exsures (ArrayIndexOutOfBoundsException) false;

Verification of modifies clauses modifies x; ensures x == 3; */ void m() { x = 3; n (); } void n() { x = 4; } Missing modifies clause Specification accepted NO

Modifies clauses Implementation of modifiable checker Extension of JML Static checking technique, based on syntax Neither sound, nor complete Fully described in separate paper (ask Néstor or me)

Future work Develop application with annotations from scratch Extension to multi-threading Automated verification technique for termination of loops Cryptographic aspects of the specification