Confined Types Encapsulation and modularity Seminar November, 2005 presented by: Guy Gueta.

Slides:



Advertisements
Similar presentations
Final and Abstract Classes
Advertisements

Objects and Classes David Walker CS 320. Advanced Languages advanced programming features –ML data types, exceptions, modules, objects, concurrency,...
Portability and Safety Mahdi Milani Fard Dec, 2006 Java.
Java™ How to Program, 9/e Presented by: Dr. José M. Reyes Álamo © Copyright by Pearson Education, Inc. All Rights Reserved.
Objects and Classes David Walker CS 320. Advanced Languages advanced programming features –ML data types, exceptions, modules, objects, concurrency,...
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
ISBN Chapter 11 Abstract Data Types and Encapsulation Concepts.
OOP in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Slides prepared by Rose Williams, Binghamton University Chapter 13 Interfaces and Inner Classes.
© 2006 Pearson Addison-Wesley. All rights reserved4-1 Chapter 4 Data Abstraction: The Walls.
Encapsulation by Subprograms and Type Definitions
Terms and Rules Professor Evan Korth New York University (All rights reserved)
Data Abstraction and Object- Oriented Programming CS351 – Programming Paradigms.
Lecture 9 Concepts of Programming Languages
OOP in Java Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
1 Chapter 8 Objects and Classes. 2 Motivations After learning the preceding chapters, you are capable of solving many programming problems using selections,
Java Security. Topics Intro to the Java Sandbox Language Level Security Run Time Security Evolution of Security Sandbox Models The Security Manager.
Programming Languages and Paradigms Object-Oriented Programming.
1 Inheritance and Polymorphism Chapter 9. 2 Polymorphism, Dynamic Binding and Generic Programming public class Test { public static void main(String[]
“is a”  Define a new class DerivedClass which extends BaseClass class BaseClass { // class contents } class DerivedClass : BaseClass { // class.
Introduction to Object-oriented programming and software development Lecture 1.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 12 Object-Oriented.
Chapter 8 More Object Concepts
Introduction to Object Oriented Programming. Object Oriented Programming Technique used to develop programs revolving around the real world entities In.
Recap (önemli noktaları yinelemek) from last week Paradigm Kay’s Description Intro to Objects Messages / Interconnections Information Hiding Classes Inheritance.
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
Java Implementation: Part 3 Software Construction Lecture 8.
Algorithm Programming Bar-Ilan University תשס"ח by Moshe Fresko.
CS200 Algorithms and Data StructuresColorado State University Part 4. Advanced Java Topics Instructor: Sangmi Pallickara
Question of the Day  On a game show you’re given the choice of three doors: Behind one door is a car; behind the others, goats. After you pick a door,
Chapter 2 Introducing Interfaces Summary prepared by Kirk Scott.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 13 Introduction to Classes.
More on Hierarchies 1. When an object of a subclass is instantiated, is memory allocated for only the data members of the subclass or also for the members.
Object Based Programming Chapter 8. 2 In This Chapter We will learn about classes Garbage Collection Data Abstraction and encapsulation.
1 Chapter 8 – Classes and Object: A Deeper Look Outline 1 Introduction 2 Implementing a Time Abstract Data Type with a Class 3 Class Scope 4 Controlling.
ADTs and C++ Classes Classes and Members Constructors The header file and the implementation file Classes and Parameters Operator Overloading.
OOP: Encapsulation,Abstraction & Polymorphism. What is Encapsulation Described as a protective barrier that prevents the code and data being randomly.
An Object-Oriented Approach to Programming Logic and Design Chapter 3 Using Methods and Parameters.
CSSE501 Object-Oriented Development. Chapter 4: Classes and Methods  Chapters 4 and 5 present two sides of OOP: Chapter 4 discusses the static, compile.
Lecture 12 March 16, The Scope of a Variable What if there are two variables with the same name? –A local or block-local variable can have the same.
Session 7 Methods Strings Constructors this Inheritance.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 26 - Java Object-Based Programming Outline 26.1Introduction.
Introduction to Java Chapter 7 - Classes & Object-oriented Programming1 Chapter 7 Classes and Object-Oriented Programming.
Classes. Constructor A constructor is a special method whose purpose is to construct and initialize objects. Constructor name must be the same as the.
ISBN Chapter 11 Abstract Data Types and Encapsulation Concepts.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 9 Inheritance and.
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 9 Java Fundamentals Objects/ClassesMethods Mon.
Inheritance CSI 1101 Nour El Kadri. OOP  We have seen that object-oriented programming (OOP) helps organizing and maintaining large software systems.
JAVA Programming (Session 4) “When you are willing to make sacrifices for a great cause, you will never be alone.” Instructor: รัฐภูมิ เถื่อนถนอม
ISBN Chapter 11 Abstract Data Types and Encapsulation Concepts.
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
Inheritance and Class Hierarchies Chapter 3. Chapter Objectives  To understand inheritance and how it facilitates code reuse  To understand how Java.
Object Oriented Programming. OOP  The fundamental idea behind object-oriented programming is:  The real world consists of objects. Computer programs.
YG - CS Concept of Encapsulation What is encapsulation? - data and functions/methods are packaged together in the class normally.
5.1 Basics of defining and using classes A review of class and object definitions A class is a template or blueprint for an object A class defines.
Reference Types CSE301 University of Sunderland Harry R Erwin, PhD.
C# Fundamentals An Introduction. Before we begin How to get started writing C# – Quick tour of the dev. Environment – The current C# version is 5.0 –
 Description of Inheritance  Base Class Object  Subclass, Subtype, and Substitutability  Forms of Inheritance  Modifiers and Inheritance  The Benefits.
Object Based Programming Chapter 8. 2 Contrast ____________________ Languages –Action oriented –Concentrate on writing ________________ –Data supports.
OOP: Encapsulation &Abstraction
Type Checking, and Scopes
Final and Abstract Classes
Java Primer 1: Types, Classes and Operators
Chapter 11 Object-Oriented Design
Lecture 9 Concepts of Programming Languages
Chapter 9 Inheritance and Polymorphism
More Object-Oriented Programming
Final and Abstract Classes
CSG2H3 Object Oriented Programming
Lecture 9 Concepts of Programming Languages
Presentation transcript:

Confined Types Encapsulation and modularity Seminar November, 2005 presented by: Guy Gueta

Writing secure code Difficult task –A lot of security problems Software systems that permit untrusted and trusted code together –Loadable components

Object-oriented An objects can be pointed by many other objects Every method can be called by an adversary Defensive style – dynamic security checks –Performance problem –Bugs Protection domains

Internal (without security checks) and external objects (with security checks) –The core code can be written without security checks –Easier for security analysis (programmer, automatic) No means to enforce such a distinction –Access modifiers (visibility of methods and fields, scope of types) –Reference to sensitive objects may leak to other protection domains

Confined Types Prevent escaping of internal objects T is confined in D iff all references to instances of T are in D Enforce static scoping of dynamic object references –stronger than “ private type ”

Achieving confinement Static constraints on the definition and use of objects Compile time (better performance, compilation errors) Java –Two additional modifiers (confined, anon) –Restrictions on programs Certain programming tasks may be clumsier –Package = protection domain –Don ’ t affect the program semantics ! –Modular (dynamic loading is possible) –Simple implementation

Security breach in JDK Untrusted code can acquire extended access rights class java.lang.Class { private Identity[] signers ; public Identity[] getSigners() { return signers ; } } java.security.IdentityScope.IdentityScope.identities() = an enumeration of all identities known to the local system

Simple fix: return a copy of the internal array Nothing guarantees that similar defects are not present in other parts of the package The attack doesn ’ t interact with Identity ( ‘ private ’ can ’ t help use) Confined types: References to identity objects will never escape from the java.security package

Anonymous Methods Do not depend on the identity of the current instance Behavior is determined by: arguments and fields Essential to allow confined types to inherit methods from unconfined parents

Anonymous Methods in Java anon Anonymous method does not invoke a non- anonymous method of the same object

 Potential callers can rely on anonymity  Constructors are a special case of instance methods  Constructors may be declared anonymous  Explicit and implicit calls are made only to anonymous constructors  The Object constructor is anonymous by definition

Anonymous methods in existing code

Confined Types

Confinement in declarations C1 – confined types have private or package-local access The unnamed global package is open to extension All subtypes of a confined type are confined

Reference widening Each instance object can be stored in a object variable (java.lang.Object is not confined) Reference widening from a confined type to an unconfined supertype shouldn ’ t be allowed // package one class A { …. } // package two confined class B extends A { ….} A a = (A)(new B()); // a can leak out of package two

Reference widening assignmentvar = expdec_type(var) > static_type(exp) method callvoid method(A a) method(exp) A > static_type(exp) returnA method () {.... ; return exp;} A > static_type(exp) cast (A)(new B)A > B

Collections Confined objects should not be stored in unconfined collections –For arrays: if T is confined then T[] is confined –For the other collections: can ’ t cast to java.lang.object Use confined collections Generics

Hidden Widening class A { protected void foo() { // store this } confined class B extends A { public void boo() { foo(); ….; } this can escape from the package Solution: confined classed are not allowed to inherit from non-trivial unconfined class Better solution with anonymous methods....

class A { public void anon foo() { // …… } confined class B extends A { public void boo() { foo(); } can be checked in the defining package

Preventing transfer from the outside Can be omitted !?

Example: Public-Key Cryptography

Other Aspects Protection domain ≠ package Generics –Reduce the need for reference widening –Less code (public-key example) Software Engineering –“ strong private ” Optimizations

Summary We saw two new language mechanisms –Confined types –Anonymous methods Enforced by a set of simple syntactic constraints which can be verified statically Can be used for controlling the dissemination of object reference