Constraining application behaviour by generating languages ELS 2015 - - PowerPoint PPT Presentation

constraining application behaviour by generating languages
SMART_READER_LITE
LIVE PREVIEW

Constraining application behaviour by generating languages ELS 2015 - - PowerPoint PPT Presentation

The Problem: apps are black boxes A Proposition: modularise! Implementation Conclusion Constraining application behaviour by generating languages ELS 2015 Paul van der Walt paul.vanderwalt@inria.fr INRIA Bordeaux 20 April, 2015 Paul van


slide-1
SLIDE 1

The Problem: apps are black boxes A Proposition: modularise! Implementation Conclusion

Constraining application behaviour by generating languages

ELS 2015

Paul van der Walt

paul.vanderwalt@inria.fr

INRIA Bordeaux

20 April, 2015

Paul van der Walt Constraining / Generating / DSLs. 1/21

slide-2
SLIDE 2

The Problem: apps are black boxes A Proposition: modularise! Implementation Conclusion

1

The Problem: apps are black boxes

2

A Proposition: modularise!

3

Implementation

4

Conclusion

Paul van der Walt Constraining / Generating / DSLs. 2/21

slide-3
SLIDE 3

The Problem: apps are black boxes A Proposition: modularise! Implementation Conclusion

What does this mobile app do?

Paul van der Walt Constraining / Generating / DSLs. 3/21

slide-4
SLIDE 4

The Problem: apps are black boxes A Proposition: modularise! Implementation Conclusion

On Android permissions

Android has a notion of “permissions”, but

Permissions apply to entire app All-or-nothing for the user

To curb privacy breaches, like

Advertising libraries regularly exfiltrate data, Twitter, LinkedIn apps stealing contact list, etc.

Paul van der Walt Constraining / Generating / DSLs. 4/21

slide-5
SLIDE 5

The Problem: apps are black boxes A Proposition: modularise! Implementation Conclusion

On Android permissions

Android has a notion of “permissions”, but

Permissions apply to entire app All-or-nothing for the user

To curb privacy breaches, like

Advertising libraries regularly exfiltrate data, Twitter, LinkedIn apps stealing contact list, etc.

We can do better :)

Paul van der Walt Constraining / Generating / DSLs. 4/21

slide-6
SLIDE 6

The Problem: apps are black boxes A Proposition: modularise! Implementation Conclusion

Running example: EvilCam!

Paul van der Walt Constraining / Generating / DSLs. 5/21

slide-7
SLIDE 7

The Problem: apps are black boxes A Proposition: modularise! Implementation Conclusion

Running example: EvilCam!

Supposedly: Takes a picture Applies sepia filter Displays it to user

Paul van der Walt Constraining / Generating / DSLs. 5/21

slide-8
SLIDE 8

The Problem: apps are black boxes A Proposition: modularise! Implementation Conclusion

Running example: EvilCam!

Supposedly: Takes a picture Applies sepia filter Displays it to user . . . and shows an advert

Paul van der Walt Constraining / Generating / DSLs. 5/21

slide-9
SLIDE 9

The Problem: apps are black boxes A Proposition: modularise! Implementation Conclusion

Running example: EvilCam!

Supposedly: Takes a picture → camera permission Applies sepia filter Displays it to user . . . and shows an advert

Paul van der Walt Constraining / Generating / DSLs. 5/21

slide-10
SLIDE 10

The Problem: apps are black boxes A Proposition: modularise! Implementation Conclusion

Running example: EvilCam!

Supposedly: Takes a picture → camera permission Applies sepia filter Displays it to user . . . and shows an advert → network permission

Paul van der Walt Constraining / Generating / DSLs. 5/21

slide-11
SLIDE 11

The Problem: apps are black boxes A Proposition: modularise! Implementation Conclusion

Potential data flow

What you hope: camera → your screen internet → fetch advert nothing more.

Paul van der Walt Constraining / Generating / DSLs. 6/21

slide-12
SLIDE 12

The Problem: apps are black boxes A Proposition: modularise! Implementation Conclusion

Potential data flow

What you hope: camera → your screen internet → fetch advert nothing more. Reality: image → stalkme.net and

nsa.gov

¨

  • Paul van der Walt

Constraining / Generating / DSLs. 6/21

slide-13
SLIDE 13

The Problem: apps are black boxes A Proposition: modularise! Implementation Conclusion

1

The Problem: apps are black boxes

2

A Proposition: modularise!

3

Implementation

4

Conclusion

Paul van der Walt Constraining / Generating / DSLs. 7/21

slide-14
SLIDE 14

The Problem: apps are black boxes A Proposition: modularise! Implementation Conclusion

How can we curb this?

The Android permission model:

Main ?? Uses Camera

? ? ? ?

Uses Network

?

Even with conservative permissions, behaviour is unpredictable.

Paul van der Walt Constraining / Generating / DSLs. 8/21

slide-15
SLIDE 15

The Problem: apps are black boxes A Proposition: modularise! Implementation Conclusion

How can we curb this?

The Android permission model:

Main ?? Uses Camera

? ? ? ?

Uses Network

?

Even with conservative permissions, behaviour is unpredictable. A better way of doing it:

Camera Filter picture WWW access Fetch Advert Compose Picture + Advert Display to screen

Platform App

Paul van der Walt Constraining / Generating / DSLs. 8/21

slide-16
SLIDE 16

The Problem: apps are black boxes A Proposition: modularise! Implementation Conclusion

Our goals

✦ Give the user clarity via spec ✦ Force the app to conform to spec ✦ Guide the developer where possible

Paul van der Walt Constraining / Generating / DSLs. 9/21

slide-17
SLIDE 17

The Problem: apps are black boxes A Proposition: modularise! Implementation Conclusion

The proposed approach

Provide a DSL to write up spec (encoding of flow diagram shown before) Provide another DSL based on that, to implement app I.e., tower of languages

Paul van der Walt Constraining / Generating / DSLs. 10/21

slide-18
SLIDE 18

The Problem: apps are black boxes A Proposition: modularise! Implementation Conclusion

Racket and #lang

uses language stmts ... (define-syntax (#%module-begin stx) (syntax-case stx () [(_ stmts ...) ; .. do something with stx ])) (provide #%module-begin ...) ... my-lang.rkt #lang s-exp "my-lang.rkt"

Paul van der Walt Constraining / Generating / DSLs. 11/21

slide-19
SLIDE 19

The Problem: apps are black boxes A Proposition: modularise! Implementation Conclusion

#lang providing #lang

Relation between specifications and implementation:

Paul van der Walt Constraining / Generating / DSLs. 12/21

slide-20
SLIDE 20

The Problem: apps are black boxes A Proposition: modularise! Implementation Conclusion

#lang providing #lang

Relation between specifications and implementation:

Paul van der Walt Constraining / Generating / DSLs. 12/21

slide-21
SLIDE 21

The Problem: apps are black boxes A Proposition: modularise! Implementation Conclusion

#lang providing #lang

Relation between specifications and implementation:

Paul van der Walt Constraining / Generating / DSLs. 12/21

slide-22
SLIDE 22

The Problem: apps are black boxes A Proposition: modularise! Implementation Conclusion

#lang providing #lang

Relation between specifications and implementation:

Paul van der Walt Constraining / Generating / DSLs. 12/21

slide-23
SLIDE 23

The Problem: apps are black boxes A Proposition: modularise! Implementation Conclusion

1

The Problem: apps are black boxes

2

A Proposition: modularise!

3

Implementation

4

Conclusion

Paul van der Walt Constraining / Generating / DSLs. 13/21

slide-24
SLIDE 24

The Problem: apps are black boxes A Proposition: modularise! Implementation Conclusion

Specifications

1 #lang s-exp "framework.rkt" 2 ;;; Specifications file, webcamspec.rkt Paul van der Walt Constraining / Generating / DSLs. 14/21

slide-25
SLIDE 25

The Problem: apps are black boxes A Proposition: modularise! Implementation Conclusion

Specifications

1 #lang s-exp "framework.rkt" 2 ;;; Specifications file, webcamspec.rkt 3 (define-context Filter

; name

4

Picture ; return type

5

[when-provided Camera]) ; subscribed to

6 7 (define-source

Camera Picture) ; built-in

8 ;; ... Paul van der Walt Constraining / Generating / DSLs. 14/21

slide-26
SLIDE 26

The Problem: apps are black boxes A Proposition: modularise! Implementation Conclusion

Specifications

1 #lang s-exp "framework.rkt" 2 ;;; Specifications file, webcamspec.rkt 3 (define-context Filter

; name

4

Picture ; return type

5

[when-provided Camera]) ; subscribed to

6 7 (define-source

Camera Picture) ; built-in

8 ;; ...

The types allow us to generate function contracts.

Paul van der Walt Constraining / Generating / DSLs. 14/21

slide-27
SLIDE 27

The Problem: apps are black boxes A Proposition: modularise! Implementation Conclusion

Implementation

The developer does the following:

1 ;;; Implementation file, webcamimpl.rkt 2 #lang s-exp "webcamspec.rkt" Paul van der Walt Constraining / Generating / DSLs. 15/21

slide-28
SLIDE 28

The Problem: apps are black boxes A Proposition: modularise! Implementation Conclusion

Implementation

The developer does the following:

1 ;;; Implementation file, webcamimpl.rkt 2 #lang s-exp "webcamspec.rkt" 3 (implement Filter Paul van der Walt Constraining / Generating / DSLs. 15/21

slide-29
SLIDE 29

The Problem: apps are black boxes A Proposition: modularise! Implementation Conclusion

Implementation

The developer does the following:

1 ;;; Implementation file, webcamimpl.rkt 2 #lang s-exp "webcamspec.rkt" 3 (implement Filter 4

(lambda (pic)

Paul van der Walt Constraining / Generating / DSLs. 15/21

slide-30
SLIDE 30

The Problem: apps are black boxes A Proposition: modularise! Implementation Conclusion

Implementation

The developer does the following:

1 ;;; Implementation file, webcamimpl.rkt 2 #lang s-exp "webcamspec.rkt" 3 (implement Filter 4

(lambda (pic)

5

(let* ([canvas (make-bitmap pic ..)])

6

; ... do magic, change colours or whatever

7

canvas)))

8 ;; ...

...which will be turned into submodules.

Paul van der Walt Constraining / Generating / DSLs. 15/21

slide-31
SLIDE 31

The Problem: apps are black boxes A Proposition: modularise! Implementation Conclusion

Separation into submodules

Compartmentalise snippets to enforce safety: C and D cannot communicate.

webcamimpl.rkt #lang "webcamspec.rkt" (implement C f) (implement D g) ... [webcamimpl.rkt] (module C-module (define C-impl f) (provide C-impl)) (module D-module (define D-impl g) (provide D-impl)) ... {evaluated}

Paul van der Walt Constraining / Generating / DSLs. 16/21

slide-32
SLIDE 32

The Problem: apps are black boxes A Proposition: modularise! Implementation Conclusion

Implementation

So, implement expands to:

1 (module webcamimpl "webcamspec.rkt" Paul van der Walt Constraining / Generating / DSLs. 17/21

slide-33
SLIDE 33

The Problem: apps are black boxes A Proposition: modularise! Implementation Conclusion

Implementation

So, implement expands to:

1 (module webcamimpl "webcamspec.rkt" 2

(module Filter-module racket/gui

Paul van der Walt Constraining / Generating / DSLs. 17/21

slide-34
SLIDE 34

The Problem: apps are black boxes A Proposition: modularise! Implementation Conclusion

Implementation

So, implement expands to:

1 (module webcamimpl "webcamspec.rkt" 2

(module Filter-module racket/gui

3

(define/contract Filter-impl

4

(-> bitmap%? bitmap%?)

Paul van der Walt Constraining / Generating / DSLs. 17/21

slide-35
SLIDE 35

The Problem: apps are black boxes A Proposition: modularise! Implementation Conclusion

Implementation

So, implement expands to:

1 (module webcamimpl "webcamspec.rkt" 2

(module Filter-module racket/gui

3

(define/contract Filter-impl

4

(-> bitmap%? bitmap%?)

5

;; the lambda from the previous step

6

)

7

(provide Filter-impl))

8

...)

Paul van der Walt Constraining / Generating / DSLs. 17/21

slide-36
SLIDE 36

The Problem: apps are black boxes A Proposition: modularise! Implementation Conclusion

Implementation

So, implement expands to:

1 (module webcamimpl "webcamspec.rkt" 2

(module Filter-module racket/gui

3

(define/contract Filter-impl

4

(-> bitmap%? bitmap%?)

5

;; the lambda from the previous step

6

)

7

(provide Filter-impl))

8

...)

webcamspec also

checks that all defines have implements and provides run

Paul van der Walt Constraining / Generating / DSLs. 17/21

slide-37
SLIDE 37

The Problem: apps are black boxes A Proposition: modularise! Implementation Conclusion

1

The Problem: apps are black boxes

2

A Proposition: modularise!

3

Implementation

4

Conclusion

Paul van der Walt Constraining / Generating / DSLs. 18/21

slide-38
SLIDE 38

The Problem: apps are black boxes A Proposition: modularise! Implementation Conclusion

Revisiting the goals

✦ The specification gives the user an idea of data flow ✦ ✦ ✦

Paul van der Walt Constraining / Generating / DSLs. 19/21

slide-39
SLIDE 39

The Problem: apps are black boxes A Proposition: modularise! Implementation Conclusion

Revisiting the goals

✦ The specification gives the user an idea of data flow ✦ Submodules ensure no unwanted communication ✦ ✦

Paul van der Walt Constraining / Generating / DSLs. 19/21

slide-40
SLIDE 40

The Problem: apps are black boxes A Proposition: modularise! Implementation Conclusion

Revisiting the goals

✦ The specification gives the user an idea of data flow ✦ Submodules ensure no unwanted communication ✦ Function contracts give hints to the developer ✦

Paul van der Walt Constraining / Generating / DSLs. 19/21

slide-41
SLIDE 41

The Problem: apps are black boxes A Proposition: modularise! Implementation Conclusion

Revisiting the goals

✦ The specification gives the user an idea of data flow ✦ Submodules ensure no unwanted communication ✦ Function contracts give hints to the developer ✦ The developer is warned if implementation doesn’t match spec

Paul van der Walt Constraining / Generating / DSLs. 19/21

slide-42
SLIDE 42

The Problem: apps are black boxes A Proposition: modularise! Implementation Conclusion

Want a demo?

– code available on my home page –

http://people.bordeaux.inria.fr/pwalt

Paul van der Walt Constraining / Generating / DSLs. 20/21

slide-43
SLIDE 43

The Problem: apps are black boxes A Proposition: modularise! Implementation Conclusion

Conclusion

DSL for tailoring DSLs? :) More confidence for user of app Relatively nice interface for app developer Not 100% practical or watertight – just a proof of concept

Use of libraries is tricky Use of eval is not permitted

Would be a great improvement on current mobile permissions systems

Paul van der Walt Constraining / Generating / DSLs. 21/21