secure distributed programming with object-capabilities in javascript

127
Secure Distributed Programming with Object-capabilities in JavaScript Mark S. Miller and the Cajadores

Upload: abie

Post on 23-Feb-2016

40 views

Category:

Documents


0 download

DESCRIPTION

Secure Distributed Programming with Object-capabilities in JavaScript. Mark S. Miller and the Cajadores. Overview. Why object-capability (ocap) security? Local ocap security in JavaScript Flexible secure mobile code Distributed crypto-caps in JavaScript - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Secure Distributed Programming  with Object-capabilities in JavaScript

Secure Distributed Programming with Object-capabilities in JavaScript

Mark S. Miller and the Cajadores

Page 2: Secure Distributed Programming  with Object-capabilities in JavaScript

Overview

Why object-capability (ocap) security?Local ocap security in JavaScriptFlexible secure mobile codeDistributed crypto-caps in JavaScriptSecure distributed object programming

Page 3: Secure Distributed Programming  with Object-capabilities in JavaScript

Early Choice. Late Despair

ACLs and OCaps start in mid ‘60s.ACLs: “Who is making this request?”OCaps: “Is this request authorized?”

‘70s: Industry took ACL fork in road.‘90s to present: Rise of Malware

Page 4: Secure Distributed Programming  with Object-capabilities in JavaScript

A Very Powerful Program

Page 5: Secure Distributed Programming  with Object-capabilities in JavaScript

A Very Powerful Program

This program can delete any file you can.

Page 6: Secure Distributed Programming  with Object-capabilities in JavaScript

Original Web

Server

Server

Frame

Frame

Browser

Link/Form GET/POST

New Page

Link/Form GET/POST

New Page

Page 7: Secure Distributed Programming  with Object-capabilities in JavaScript

Ajax = Mobile code + async msgs

Server

Server

Frame

Frame

Browser

XHR GET/POST

XHR Response

XHR GET/POST

XHR Response

Web services

Page 8: Secure Distributed Programming  with Object-capabilities in JavaScript

Kludging Towards Distributed Objects

Server

Server

Frame

Frame

Browser

XHR GET/POST

XHR Response, Comet

XHR GET/POST

XHR Response, Comet

Web servicesJSONPFragment

tricks

Page 9: Secure Distributed Programming  with Object-capabilities in JavaScript

A Web of Distributed Objects

Server

Server

Frame

Frame

Browser

XHR GET/POST

XHR Response, SSE

XHR GET/POST

XHR Response, SSE

Web servicesCross-Origin XHRwith UMP

postMessage

Page 10: Secure Distributed Programming  with Object-capabilities in JavaScript

A Web of Distributed Objects

Mobile messages, code, objects, references

Page 11: Secure Distributed Programming  with Object-capabilities in JavaScript

A Web of Distributed Objects

Page 12: Secure Distributed Programming  with Object-capabilities in JavaScript

A Web of Distributed Objects

Page 13: Secure Distributed Programming  with Object-capabilities in JavaScript

A Web of Distributed Objects

Page 14: Secure Distributed Programming  with Object-capabilities in JavaScript

A Very Powerful Email Message

Page 15: Secure Distributed Programming  with Object-capabilities in JavaScript

A Very Powerful Email Message<html> <head> <title>Basic Mashup</title> <script> function animate(id) { var element = document.getElementById(id); var textNode = element.childNodes[0]; var text = textNode.data; var reverse = false; element.onclick = function() { reverse = !reverse; }; setInterval(function() { textNode.data = text = reverse ? text.substring(1) + text[0] : text[text.length-1] + text.substring(0, text.length-1); }, 100); }</script> </head> <body onload="animate('target')"> <pre id="target">Hello Programmable World! </pre></body> </html>

Page 16: Secure Distributed Programming  with Object-capabilities in JavaScript

Active Content: Mobile Code as Media

<html> <head> <title>Basic Mashup</title> <script> function animate(id) { var element = document.getElementById(id); var textNode = element.childNodes[0]; var text = textNode.data; var reverse = false; element.onclick = function() { reverse = !reverse; }; setInterval(function() { textNode.data = text = reverse ? text.substring(1) + text[0] : text[text.length-1] + text.substring(0, text.length-1); }, 100); }</script> </head> <body onload="animate('target')"> <pre id="target">Hello Programmable World! </pre></body> </html>

Page 17: Secure Distributed Programming  with Object-capabilities in JavaScript

The Road Not Taken

?

Page 18: Secure Distributed Programming  with Object-capabilities in JavaScript

The Road Not Taken

?

Page 19: Secure Distributed Programming  with Object-capabilities in JavaScript

The Road Not Taken

?

Page 20: Secure Distributed Programming  with Object-capabilities in JavaScript

The Road Not Taken

? ?

Page 21: Secure Distributed Programming  with Object-capabilities in JavaScript

Security as Extreme Modularity

Modularity: Avoid needless dependenciesSecurity: Avoid needless vulnerabilitiesVulnerability is a form of dependency

Modularity:Principle of info hiding - need to know

Security:Principle of least authority - need to do

Page 22: Secure Distributed Programming  with Object-capabilities in JavaScript

Connectivity by…… Introduction

ref to Carolref to Bobdecides to share

… Parenthood… Endowment… Initial Conditions

Alice says: bob.foo(carol)

How might object Bob come to know object Carol?

Page 23: Secure Distributed Programming  with Object-capabilities in JavaScript

OCaps: Small step from pure objects

Memory safety and encapsulation+ Effects only by using held references+ No powerful references by default

Page 24: Secure Distributed Programming  with Object-capabilities in JavaScript

OCaps: Small step from pure objects

Memory safety and encapsulation+ Effects only by using held references+ No powerful references by default Reference graph ≡ Access graph Only connectivity begets connectivity Natural Least Authority OO expressiveness for security patterns

Page 25: Secure Distributed Programming  with Object-capabilities in JavaScript

function makeCounter() { var count = 0; return { incr: function() { return ++count; }, decr: function() { return --count; } };}

makeCounter

count

incr

decr

count

incr

decr

count

incr

decr

Objects as Closures in JavaScript

Page 26: Secure Distributed Programming  with Object-capabilities in JavaScript

Objects as Closures in JavaScript

function makeCounter() { var count = 0; return { incr: function() { return ++count; }, decr: function() { return --count; } };}

makeCounter

count

incr

decr

count

incr

decr

count

incr

decr

A record of closures hiding state is a fine representation of an

object of methods hiding instance vars

Page 27: Secure Distributed Programming  with Object-capabilities in JavaScript

function makeCounter() { var count = 0; return { incr: function() { return ++count; }, decr: function() { return --count; } };}

• Scoping confusions• Encapsulation leaks• Pervasive mutability

makeCounter

count

incr

decr

count

incr

decr

count

incr

decr

Objects as Closures in EcmaScript 3

Page 28: Secure Distributed Programming  with Object-capabilities in JavaScript

Defensive Objects in SES on ES5“use strict”;function makeCounter() { var count = 0; return def({ incr: function() { return ++count; }, decr: function() { return --count; } });}

makeCounter

count

incr

decr

count

incr

decr

count

incr

decr

A tamper-proof record of lexical closures encapsulating

state is a defensive object

Page 29: Secure Distributed Programming  with Object-capabilities in JavaScript
Page 30: Secure Distributed Programming  with Object-capabilities in JavaScript
Page 31: Secure Distributed Programming  with Object-capabilities in JavaScript
Page 32: Secure Distributed Programming  with Object-capabilities in JavaScript

Turning EcmaScript 5 into SES

<script src=“initSES.js”></script>

Monkey patch away bad non-std behaviors

Remove non-whitelisted primordials Install leaky WeakMap emulation Make virtual global root Freeze whitelisted global variables• Replace eval & Function with safe

alternatives Freeze accessible primordials

Page 33: Secure Distributed Programming  with Object-capabilities in JavaScript

No powerful references by default

Alice says: var bobSrc = //site B var carolSrc = //site C var bob = eval(bobSrc); var carol = eval(carolSrc);

bob

carol

Alice Bob

Carol

Page 34: Secure Distributed Programming  with Object-capabilities in JavaScript

No powerful references by default

bob

carol

Alice

Bob and Carol are confined. Only Alice controls how they can interact or get more connected.

Bob

Carol

Alice says: var bobSrc = //site B var carolSrc = //site C var bob = eval(bobSrc); var carol = eval(carolSrc);

Page 35: Secure Distributed Programming  with Object-capabilities in JavaScript

No powerful references by default

Alice says:bob

carol

Bob

Carol

Page 36: Secure Distributed Programming  with Object-capabilities in JavaScript

Bob

Carol

bob

carol

counter

Only connectivity begets connectivity

Alice says: var counter = makeCounter(); bob(counter.incr); carol(counter.decr); bob = carol = null;countcountcount

incr

decr

Page 37: Secure Distributed Programming  with Object-capabilities in JavaScript

Bob

Carol

bob

carol

counter

Only connectivity begets connectivity

Alice says: var counter = makeCounter(); bob(counter.incr); carol(counter.decr); bob = carol = null;countcountcount

incr

decr

Bob can only count up and see result. Carol only down.

Alice can only do both.

Page 38: Secure Distributed Programming  with Object-capabilities in JavaScript

Bob

Carol

bob

carol

counter

Only connectivity begets connectivity

Alice says: var counter = makeCounter(); bob(counter.incr); carol(counter.decr); bob = carol = null;countcountcount

incr

decr

Express policy by the behavior of the objects you provide.

Page 39: Secure Distributed Programming  with Object-capabilities in JavaScript

Dr. SESDistributed Resilient Secure

EcmaScript

Linguistic abstraction for safe messagingStretch reference graph between event loops &

machinesCrypto analog of memory safety

SES + Promise library + infix “!” syntax(“Q” Library usable today without “!” syntax)

Page 40: Secure Distributed Programming  with Object-capabilities in JavaScript

Unguessable URLs as Crypto-Caps

https://www.example.com/app/#mhbqcmmva5ja3

How are secrets like object references?

Page 41: Secure Distributed Programming  with Object-capabilities in JavaScript

Dr. SESDistributed Resilient Secure

EcmaScript

var result = bob.foo(carol); Local-only immediate callvar resultP = bobP ! foo(carol); Eventual send

Page 42: Secure Distributed Programming  with Object-capabilities in JavaScript

Dr. SESDistributed Resilient Secure

EcmaScript

var result = bob.foo(carol); Local-only immediate callvar resultP = bobP ! foo(carol); Eventual sendvar result = bob.foo; Local-only immediate getvar resultP = bobP ! foo; Eventual get

Page 43: Secure Distributed Programming  with Object-capabilities in JavaScript

Dr. SESDistributed Resilient Secure

EcmaScript

var resultP = bobP ! foo(carol); Eventual send

var resultP = bobP ! foo; Eventual get

Page 44: Secure Distributed Programming  with Object-capabilities in JavaScript

Dr. SESDistributed Resilient Secure

EcmaScript

var resultP = bobP ! foo(carol); Eventual sendvar resultP = bobP ! foo; Eventual get

Page 45: Secure Distributed Programming  with Object-capabilities in JavaScript

Q(resultP).when(function(result) { …result…}, function (ex) { …ex…});

Register for notification

Dr. SESDistributed Resilient Secure

EcmaScript

var resultP = bobP ! foo(carol); Eventual sendvar resultP = bobP ! foo; Eventual get

Page 46: Secure Distributed Programming  with Object-capabilities in JavaScript

Q(resultP).when(function(result) { …result…}, function (ex) { …ex…});

xhr.onreadystatechange = …

Async object ops as JSON/REST ops

var resultP = bobP ! foo(carol); POST https://…q=foo {…}var resultP = bobP ! foo; GET https://…q=foo

Page 47: Secure Distributed Programming  with Object-capabilities in JavaScript

Distributed Secure Currency

$100 $0

$200

var paymentP = myPurse ! makePurse();paymentP ! deposit(10, myPurse);var goodP = bobP ! buy(desc, paymentP);

buy

$90$10

return Q(paymentP).when(function(p) { return Q(myPurse ! deposit(10, p)).when(function(_) { return good; }, …

Page 48: Secure Distributed Programming  with Object-capabilities in JavaScript

Money as “factorial” of secure coding

function makeMint() { var amp = WeakMap(); return function mint(balance) { var purse = def({ getBalance: function() { return balance; }, makePurse: function() { return mint(0); }, deposit: function(amount, src) { Nat(balance + amount); amp.get(src)(Nat(amount)); balance += amount; } }); function decr(amount) { balance = Nat(balance – amount); } amp.set(purse, decr); return purse; }}

No explicit crypto

Alice Bobbuy

makeMint

mintmintpurse decrpurse decrpurse decr

balance

amp

Page 49: Secure Distributed Programming  with Object-capabilities in JavaScript

Causeway Distributed Debugger

Sourcilloscope

Page 50: Secure Distributed Programming  with Object-capabilities in JavaScript

Causeway Distributed Debugger

Causality Grid

Page 51: Secure Distributed Programming  with Object-capabilities in JavaScript

Causeway Distributed Debugger

Causality Grid at Scale

Page 52: Secure Distributed Programming  with Object-capabilities in JavaScript

Authorization by Designation

CapDesk

Page 53: Secure Distributed Programming  with Object-capabilities in JavaScript

Authorization by Designation

Belay

Page 54: Secure Distributed Programming  with Object-capabilities in JavaScript

Questions?

Why object-capability (ocap) security?Local ocap security in JavaScriptFlexible secure mobile codeDistributed crypto-caps in JavaScriptSecure distributed programming

Page 55: Secure Distributed Programming  with Object-capabilities in JavaScript
Page 56: Secure Distributed Programming  with Object-capabilities in JavaScript

How to lose an arms race

Page 57: Secure Distributed Programming  with Object-capabilities in JavaScript

How to lose an arms race

Page 58: Secure Distributed Programming  with Object-capabilities in JavaScript

Doomed to never ending tinkering?

Page 59: Secure Distributed Programming  with Object-capabilities in JavaScript

Doomed to never ending tinkering?

Identity-centric accessHTTP auth infoclient side certs

script, img, fragment holes

Cookiesaugments attacker’s authority

confused deputiesOrigin: header “fix”

subtler confused deputies

Page 60: Secure Distributed Programming  with Object-capabilities in JavaScript

Doomed to never ending tinkering?

Identity-centric accessHTTP auth infoclient side certs

script, img, fragment holes

Cookiesaugments attacker’s authority

confused deputiesOrigin: header “fix”

subtler confused deputies

Identity-centric vs. Authorization-centric

Page 61: Secure Distributed Programming  with Object-capabilities in JavaScript

Running ES5 & SES on old browsers

Page 62: Secure Distributed Programming  with Object-capabilities in JavaScript

Future objects on old browsers

Page 63: Secure Distributed Programming  with Object-capabilities in JavaScript

OCaps in JavaScript

Caja on EcmaScript 3One of the hardest oo languages to secure.Complex server-side translator. Some runtime

overhead.Successful large scale deployment.

Secure EcmaScript (SES) on EcmaScript 5One of the easiest oo languages to secure.<script src=“initSES.js”></script>Simple client-side init and verifier. No runtime

overhead.

Page 64: Secure Distributed Programming  with Object-capabilities in JavaScript

Safe Mobile Messages: Uniform XHR

As in “Uniform Resource Locator”Designation (ideally) independent of requestor

contextIgnore browser’s “helpful” extras

HTTP Auth info, client side certs, cookies, Origin: header,

Like IP address: use only for forensics & emergencies

Authorize based only on payloadHTTPS URL or request body – info the requestor

knowsWaive response “protection”

Access-Control-Allow-Origin: *

Page 65: Secure Distributed Programming  with Object-capabilities in JavaScript

The other half of the object revolutionProtect object from world Protect world from objectResponsibility driven design

Authority driven design

Avoid needless coupling Avoid needless vulnerability

Information hiding Principle of Least AuthorityAvoid global variables Forbid mutable static stateProcedural, data, control, …

…, and access abstractions

Patterns and frameworks Patterns of safe cooperation

Say what you mean Mean only what you say

Page 66: Secure Distributed Programming  with Object-capabilities in JavaScript
Page 67: Secure Distributed Programming  with Object-capabilities in JavaScript

Bringing Object-orientationto Security Programming

Mark S. Miller and the Cajadores

Page 68: Secure Distributed Programming  with Object-capabilities in JavaScript

Overview: Bottom up by Layers

Composing Networks of GamesSmart Contracts as GamesDimensions & Taxonomy of Electronic

RightsPatterns of Safe CooperationAccess Abstractions and CompositionsObject-capabilities (ocaps)Objects, References, Messages

Page 69: Secure Distributed Programming  with Object-capabilities in JavaScript

How do I designate thee?by Introduction

ref to Carolref to Bobdecides to share

by Parenthoodby Endowmentby Initial

ConditionsHow might object Bob come to know of object

Carol?

Page 70: Secure Distributed Programming  with Object-capabilities in JavaScript

How do I designate thee?by Introduction

ref to Carolref to Bobdecides to share

by Parenthoodby Endowmentby Initial

Conditions

Alice says: bob.foo(carol)

Page 71: Secure Distributed Programming  with Object-capabilities in JavaScript

How do I designate thee?by Introduction

ref to Carolref to Bobdecides to share

by Parenthoodby Endowmentby Initial

Conditions

Alice says: bob.foo(carol)

Page 72: Secure Distributed Programming  with Object-capabilities in JavaScript

How do I designate thee?by Introduction

ref to Carolref to Bobdecides to share

by Parenthoodby Endowmentby Initial

Conditions

Alice says: bob.foo(carol)

Page 73: Secure Distributed Programming  with Object-capabilities in JavaScript

How do I designate thee?by Introduction

ref to Carolref to Bobdecides to share

by Parenthoodby Endowmentby Initial Conditions

Alice says: bob.foo(carol)

Page 74: Secure Distributed Programming  with Object-capabilities in JavaScript

How do I designate thee?by Introduction

ref to Carolref to Bobdecides to share

by Parenthoodby Endowmentby Initial Conditions

Alice says: bob.foo(carol)

Page 75: Secure Distributed Programming  with Object-capabilities in JavaScript

How do I designate thee?by Introduction

ref to Carolref to Bobdecides to share

by Parenthoodby Endowmentby Initial Conditions

Bob says: var carol = { ... };

Page 76: Secure Distributed Programming  with Object-capabilities in JavaScript

How do I designate thee?by Introduction

ref to Carolref to Bobdecides to share

by Parenthoodby Endowmentby Initial Conditions

Alice says: var bob = { ... carol ... };

Page 77: Secure Distributed Programming  with Object-capabilities in JavaScript

How do I designate thee?by Introduction

ref to Carolref to Bobdecides to share

by Parenthoodby Endowmentby Initial Conditions

At t0:

Page 78: Secure Distributed Programming  with Object-capabilities in JavaScript

OCaps: Small step from pure objects

Memory safety and encapsulation+ Effects only by using held references+ No powerful references by default

Page 79: Secure Distributed Programming  with Object-capabilities in JavaScript

OCaps: Small step from pure objects

Memory safety and encapsulation+ Effects only by using held references+ No powerful references by default Reference graph ≡ Access graph Only connectivity begets connectivity OO expressiveness for security patterns

Page 80: Secure Distributed Programming  with Object-capabilities in JavaScript

Objects as Closures

function makeCounter() { var count = 0; return { incr: function() { return ++count; }, decr: function() { return --count; } };}

makeCounter

count

incr

decr

count

incr

decr

count

incr

decr

Page 81: Secure Distributed Programming  with Object-capabilities in JavaScript

Objects as Closures

function makeCounter() { var count = 0; return { incr: function() { return ++count; }, decr: function() { return --count; } };}

makeCounter

count

incr

decr

count

incr

decr

count

incr

decr

A record of closures hiding state is a fine representation of an

object of methods hiding instance vars

Page 82: Secure Distributed Programming  with Object-capabilities in JavaScript

Objects as Closures in SES on ES5

“use strict”;function makeCounter() { var count = 0; return def({ incr: function() { return ++count; }, decr: function() { return --count; } });}

makeCounter

count

incr

decr

count

incr

decr

count

incr

decr

A tamper-proof record of lexical closures encapsulating

state is a defensive object

Page 83: Secure Distributed Programming  with Object-capabilities in JavaScript

Turning EcmaScript 5 into SES

<script src=“initSES.js”></script>

Monkey patch away bad non-std behaviors

Remove non-whitelisted primordials Install leaky WeakMap emulation Make virtual global root Freeze whitelisted global variables• Replace eval & Function with safe

alternatives Freeze accessible primordials

Page 84: Secure Distributed Programming  with Object-capabilities in JavaScript

Revocable Function Forwarderfunction makeFnCaretaker(target) { return def({ wrapper: function(…args) { return target(…args); }, revoke: function() { target = null; } });}

makeCaretaker

target

wrapperrevoke

target

wrapperrevoke

target

wrapperrevoke

target

wrapperrevoke

target

wrapperrevoke

target

wrapperrevoke

Page 85: Secure Distributed Programming  with Object-capabilities in JavaScript

Alice

Unconditional AccessAlice says: bob.foo(carol);

Bob

Carol

foo

Grants Bob full access to Carol forever

Page 86: Secure Distributed Programming  with Object-capabilities in JavaScript

Alice

Revocability ≡ Temporal attenuation

Alice says: var ct = makeCaretaker(carol); bob.foo(ct.wrapper);

target

wrapperrevoke

Bob

Carol

foo

Page 87: Secure Distributed Programming  with Object-capabilities in JavaScript

Alice

Revocability ≡ Temporal attenuation

Alice says: var ct = makeCaretaker(carol); bob.foo(ct.wrapper); //…

target

wrapperrevoke

Bob

Carol

Page 88: Secure Distributed Programming  with Object-capabilities in JavaScript

Alice Alice says: var ct = makeCaretaker(carol); bob.foo(ct.wrapper); //… ct.revoke();

target

wrapperrevoke

Bob

Carol

Revocability ≡ Temporal attenuation

Page 89: Secure Distributed Programming  with Object-capabilities in JavaScript

Alice Alice says: var ct = makeCaretaker(carol); bob.foo(ct.wrapper); //… ct.revoke();

target

wrapperrevoke

Bob

Carol

Revocability ≡ Temporal attenuation

Page 90: Secure Distributed Programming  with Object-capabilities in JavaScript

Alice

Attenuators ≡ Access Abstractions

Alice says: var ct = makeCaretaker(carol); bob.foo(ct.wrapper);

Bob

CarolExpress security policy by the behavior of the objects you provide

foo

Page 91: Secure Distributed Programming  with Object-capabilities in JavaScript

Abstractions extend vocabularyPrimitives Abstraction Forms Extended

Vocabulary+, ., [] procedural

abstractionfoo(bar, baz), …

int, struct, array data abstraction Point, Window, …

if, while, switch control abstraction addListener, visitor, …

points-to access abstraction caretaker, membrane, …

Page 92: Secure Distributed Programming  with Object-capabilities in JavaScript

Alice

Membranes: Transitive Interposition

function makeFnMembrane(target) { var enabled = true; function wrap(wrapped) { if (wrapped !== Object(wrapped)) { return wrapped; } return function(…args) { if (!enabled) { throw new Error(“revoked”); } return wrap(wrapped(…args.map(wrap)); } } return def({ wrapper: wrap(target), revoke: function() { enabled = false; } });}

Bob

Carol

bar

Dave

Page 93: Secure Distributed Programming  with Object-capabilities in JavaScript

Attenuators Compose

function makeROFile(file) { return def({ read: file.read, getLength: file.getLength });}var rorFile = makeROFile(revocableFile);

Page 94: Secure Distributed Programming  with Object-capabilities in JavaScript

No powerful references by default

Alice says: var bobSrc = //site B var carolSrc = //site C var bob = eval(bobSrc); var carol = eval(carolSrc);

bob

carol

Alice Bob

Carol

Page 95: Secure Distributed Programming  with Object-capabilities in JavaScript

No powerful references by default

bob

carol

Alice

Bob and Carol are confined. Only Alice controls how they can interact or get more connected.

Bob

Carol

Alice says: var bobSrc = //site B var carolSrc = //site C var bob = eval(bobSrc); var carol = eval(carolSrc);

Page 96: Secure Distributed Programming  with Object-capabilities in JavaScript

No powerful references by default

Alice says:bob

carol

Bob

Carol

Page 97: Secure Distributed Programming  with Object-capabilities in JavaScript

Bob

Carol

bob

carol

counter

Only connectivity begets connectivity

Alice says: var counter = makeCounter(); bob(counter.incr); carol(counter.decr); bob = carol = null;countcountcount

incr

decr

Page 98: Secure Distributed Programming  with Object-capabilities in JavaScript

Bob

Carol

bob

carol

counter

Only connectivity begets connectivity

Alice says: var counter = makeCounter(); bob(counter.incr); carol(counter.decr); bob = carol = null;countcountcount

incr

decr

Bob can only count up and see result. Carol only down.Alice can only do both.

Page 99: Secure Distributed Programming  with Object-capabilities in JavaScript

Membrane eval → compartment

var compartment = makeMembrane(eval);

var vbob = compartment.wrapper(bobSrc);

Alice Bob

Page 100: Secure Distributed Programming  with Object-capabilities in JavaScript

Membrane eval → compartment

var compartment = makeMembrane(eval);

var vbob = compartment.wrapper(bobSrc);

//…

Alice Bob

Page 101: Secure Distributed Programming  with Object-capabilities in JavaScript

Membrane eval → compartment

var compartment = makeMembrane(eval);

var vbob = compartment.wrapper(bobSrc);

//…compartment.revoke();

Alice Bob GC

Page 102: Secure Distributed Programming  with Object-capabilities in JavaScript

Composing Authority

∪?

Usuallyintersection

Subset

Page 103: Secure Distributed Programming  with Object-capabilities in JavaScript

Rights Amplification

≥∪∪

Authority conditional on other possessions.

Enables more expressive power.

Page 104: Secure Distributed Programming  with Object-capabilities in JavaScript

Rights Amplificationfunction makeBrand() { var amp = WeakMap(); return def({ seal: function(payload) { var box = def({}); amp.set(box, payload); return box; }, unseal: function(box) { return amp.get(box); } });}

Alice Bobfoo

makeBrand

amp

seal unsealseal unseal

payload

box

payload

box

payload

boxamp

Page 105: Secure Distributed Programming  with Object-capabilities in JavaScript

Rights Amplificationfunction makeBrand() { var amp = WeakMap(); return def({ seal: function(payload) { var box = def({}); amp.set(box, payload); return box; }, unseal: function(box) { return amp.get(box); } });}

Crypto patterns without cryptomakeBrand() generate key

pairseal method encryption key

unseal method decryption key

payload plaintext

box cyphertext

Page 106: Secure Distributed Programming  with Object-capabilities in JavaScript

Distributed Secure Currency

$100 $200

Page 107: Secure Distributed Programming  with Object-capabilities in JavaScript

Distributed Secure Currency

$100 $200

var paymentP = myPurse ! makePurse();

Page 108: Secure Distributed Programming  with Object-capabilities in JavaScript

Distributed Secure Currency

$100 $200

var paymentP = myPurse ! makePurse();

makePurse

Page 109: Secure Distributed Programming  with Object-capabilities in JavaScript

Distributed Secure Currency

$100 $0

$200

var paymentP = myPurse ! makePurse();

Page 110: Secure Distributed Programming  with Object-capabilities in JavaScript

Distributed Secure Currency

$100 $0

$200

var paymentP = myPurse ! makePurse();paymentP ! deposit(10, myPurse);

Page 111: Secure Distributed Programming  with Object-capabilities in JavaScript

Distributed Secure Currency

$100 $0

$200

var paymentP = myPurse ! makePurse();paymentP ! deposit(10, myPurse);

deposit

Page 112: Secure Distributed Programming  with Object-capabilities in JavaScript

Distributed Secure Currency

$100 $0

$200

var paymentP = myPurse ! makePurse();paymentP ! deposit(10, myPurse);

$90$10

Page 113: Secure Distributed Programming  with Object-capabilities in JavaScript

Distributed Secure Currency

$100 $0

$200

var paymentP = myPurse ! makePurse();paymentP ! deposit(10, myPurse);var goodP = bobP ! buy(desc, paymentP);

$90$10

Page 114: Secure Distributed Programming  with Object-capabilities in JavaScript

Distributed Secure Currency

$100 $0

$200

var paymentP = myPurse ! makePurse();paymentP ! deposit(10, myPurse);var goodP = bobP ! buy(desc, paymentP);

buy

$90$10

Page 115: Secure Distributed Programming  with Object-capabilities in JavaScript

Distributed Secure Currency

$100 $0

$200

var paymentP = myPurse ! makePurse();paymentP ! deposit(10, myPurse);var goodP = bobP ! buy(desc, paymentP);

$90$10

return Q(paymentP).when(function(p) {

Page 116: Secure Distributed Programming  with Object-capabilities in JavaScript

Distributed Secure Currency

$100 $0

$200

var paymentP = myPurse ! makePurse();paymentP ! deposit(10, myPurse);var goodP = bobP ! buy(desc, paymentP);

$90$10

return Q(paymentP).when(function(p) { return Q(myPurse ! deposit(10, p)).when(function(_) {

Page 117: Secure Distributed Programming  with Object-capabilities in JavaScript

Distributed Secure Currency

$100 $0

$200

var paymentP = myPurse ! makePurse();paymentP ! deposit(10, myPurse);var goodP = bobP ! buy(desc, paymentP);

$90$10

deposit

return Q(paymentP).when(function(p) { return Q(myPurse ! deposit(10, p)).when(function(_) {

Page 118: Secure Distributed Programming  with Object-capabilities in JavaScript

Distributed Secure Currency

$100 $0

$200

var paymentP = myPurse ! makePurse();paymentP ! deposit(10, myPurse);var goodP = bobP ! buy(desc, paymentP);

$90 $210

return Q(paymentP).when(function(p) { return Q(myPurse ! deposit(10, p)).when(function(_) {

Page 119: Secure Distributed Programming  with Object-capabilities in JavaScript

Distributed Secure Currency

$100 $0

$200

var paymentP = myPurse ! makePurse();paymentP ! deposit(10, myPurse);var goodP = bobP ! buy(desc, paymentP);

return Q(paymentP).when(function(p) { return Q(myPurse ! deposit(10, p)).when(function(_) { return good; }, …

$90 $210

Page 120: Secure Distributed Programming  with Object-capabilities in JavaScript

Money as “factorial” of secure coding

function makeMint() { var amp = WeakMap(); return function mint(balance) { var purse = def({ getBalance: function() { return balance; }, makePurse: function() { return mint(0); }, deposit: function(amount, src) { Nat(balance + amount); amp.get(src)(Nat(amount)); balance += amount; } }); function decr(amount) { balance = Nat(balance – amount); } amp.set(purse, decr); return purse; }}

No explicit crypto

Alice Bobbuy

makeMint

mintmintpurse decrpurse decrpurse decr

balance

amp

Page 121: Secure Distributed Programming  with Object-capabilities in JavaScript

Dimensions of Electronic Rights

Object reference• Shared• Specific• Opaque• Exercisable

Money• Exclusive• Fungible• Assayable• Symbolic

Page 122: Secure Distributed Programming  with Object-capabilities in JavaScript

Smart Contracts as Board Games

NegotiationDesign a game both expect to win

Players make moves, but only “legal” ones

Move changes state of boardBoard-state determines move “legality”

ERights are “pieces” placed on boardGame escrows pieces, Pieces/ERights released only by play

Page 123: Secure Distributed Programming  with Object-capabilities in JavaScript

A Simple Exchange Game

Page 124: Secure Distributed Programming  with Object-capabilities in JavaScript

The Five Players

Page 125: Secure Distributed Programming  with Object-capabilities in JavaScript

A Covered Call Option

Page 126: Secure Distributed Programming  with Object-capabilities in JavaScript

Composing Networks of Games

Page 127: Secure Distributed Programming  with Object-capabilities in JavaScript

Questions?

Composing Networks of GamesSmart Contracts as GamesDimensions & Taxonomy of Electronic

RightsPatterns of Safe CooperationAccess Abstractions and CompositionsObject-capabilities (ocaps)Objects, References, Messages