Embedded security, case of AGL · January 31th 2019 embedded security, case of AGL 10...

109
Embedded security Case of AGL (A utomotive G rade L inux) November 22th, 2019 José Bollo Security Technical Lead [email protected]

Transcript of Embedded security, case of AGL · January 31th 2019 embedded security, case of AGL 10...

Embedded securityCase of AGL

(Automotive Grade Linux)

November 22th, 2019

José Bollo Security Technical [email protected]

January 31th 2019 embedded security, case of AGL 2

IoT.bzh

Fulup Stéphane Manuel Yannick José

October 2015

October 2018

● Mostly dedicated to AGL

● https://iot.bzh/en/● http://github.com/iotbzh

LORIENT

January 31th 2019 embedded security, case of AGL 3

Overview embedded security

January 31th 2019 embedded security, case of AGL 4

Secure boot

● Cascade of signed/verified (boot)loader● System embeds root keys

Root Loader

OS 1

OS 2

HASH(PK1)

PK1 & CERT

PK2 & CERT

verify

verify

BOOTLOADER

verifyLoadand

verify

maskROM

January 31th 2019 embedded security, case of AGL 5

Secure boot encrypted

● Cascade of signed/verified (boot)loader● System embeds root keys

Root Loader

OS 1

OS 2

HASH(PK1)

PK1 & CERT

PK2 & CERT

verify

verify

BOOTLOADER

verifyLoadand

verify

KEY

decrypt

maskROM

January 31th 2019 embedded security, case of AGL 6

Secure debug

● The standard JTAG debugging interface can be disabled (eFuse or maskROM)

● Nevertheless, on some device, it is possible to activate JTAG by loading an activator, potentially specific to the device (using a “device id”)

January 31th 2019 embedded security, case of AGL 7

Cryptography

● Security implies use of cryptography● Use of cryptography implies serious

computations● Hardware acceleration is cool● Hardware protection of secrets might be

needed

January 31th 2019 embedded security, case of AGL 8

Trusted Execute Environment

● Separation between a trusted execution environment and a not trusted one

● Trusted environment can:

– Keep secrets

– Use reserved resource

– Measure and monitor integrity of the system

– Example: DRM, Cryptography● Special OS exist to run TEE

January 31th 2019 embedded security, case of AGL 9

Trusted Execute Environment

● On ARM: low cost implementation named TrustZone

● Free OS exist for TrustZone: OP-TEE

TrustZone Normal zone

OP-TEE LINUX

Trusted Service

Client

January 31th 2019 embedded security, case of AGL 10

Virtualization

● Virtualization can be used to separate complex systems into simplest parts, specially when critical functions have to be separated: hardware is split between several systems (network / CAN bus / graphic)

● Virtualization can benefit of hardware facilities (including GPU features)

● Management of virtualization is the role of the hypervisor

● Trusted Execution Environment is not an hypervisor and should generally be started before hypervisor

January 31th 2019 embedded security, case of AGL 11

Integrity Measurement

● After boot, systems can also include measurement of their integrity to detect malicious changes

● Linux has 2 security modules to ensure integrity measurement:

– IMA (integity measurement architecture)

– EVM (Extended Validation Module)

January 31th 2019 embedded security, case of AGL 12

Overview of AGL system

January 31th 2019 embedded security, case of AGL 13

AGL 6.0 Funky Flounder

identity audio-4a

persistence

weather

unicens

nfcnetwork

mediascanner

mediaplayergeoclue

bluetooth

windowmanager

low-can

homescreen

LINUX KERNEL

AG

L fr

amew

ork

Sys

tem

D

(pulseaudio) Network-Manager ...

geocluebluez gstreamer

...

DASHBOARD HOMESCREEN LAUNCHER

MEDIAPLAYER HVAC MIXER

SETTINGS RADIO NAVI

PHONE POI ...

upstreamservices

AGLservices

AGL applications

January 31th 2019 embedded security, case of AGL 14

Micro service architecture

APPLICATION

SECURITYCONTEXTC

SERVICE

SECURITYCONTEXTD

SERVICE

SECURITYCONTEXTB

APPLICATION

SECURITYCONTEXTA

interconnection

dbus, ws,bus1, tls,

...

network

Applications and services are running isolated one another by their smack security context

The communication between applications is controlled by policy (framework, firewall, gateway, OAuth, openid connect)

Access to service features is controlled by permission enforcement mechanism (cynagora, OAuth)

Services are like applications

January 31th 2019 embedded security, case of AGL 15

Mechanisms of security

● Mandatory Access Control with SMACK

– Simple Mandatory Access Control Kernel

– Strong isolation of kernel objects (files, sockets)● Network firewall and filtering

– Using netherd and netfilter● Permission database cynagora

– Filtering permission

– User consent mechanism● User credential management

– Oauth and OpenID Connect

January 31th 2019 embedded security, case of AGL 16

Global view of security

LINUX KERNEL

PBACPermission Based

Access Control

Access Controlprovides

operations tocontrol accesses

+has_access()

MACMandatory Access

Control

DACDiscretionary

Access Control

SMACKSimple Mandatory

Access ControlKernel

CYNARAACL

Standard LinuxAccess Control

NSBACNameSpace Based

Access Control(containers)

January 31th 2019 embedded security, case of AGL 17

Mechanisms of security

Protected Service

LINUX KERNEL

Legitimate application BlackHat application

System resource

The permission database

Cynagora helps to protect

services

Smack linux security module helps to protect

system resources

DENIED

DENIED

GRANTED

GRANTED

January 31th 2019 embedded security, case of AGL 18

Permission checking

: SOLUTION : SERVICE

CONNECT

INVOKE METHOD

SIGNAL EVENT

return from INVOKE

Subject to permission to connect to the service

Subject to permission to invoke the METHOD of the service

Subject to permission to receive EVENT of the service

: CLIENT

January 31th 2019 embedded security, case of AGL 19

Permission and composition of services

: SOLUTION X : SERVICE Y : SERVICE<<depends>> <<depends>>

Policy for Y is: requires permission P

About permission P, the policy for X is either: - P is required by transitivity - P is a hidden requirement of X

AGL framework takes care of composition of permissions. Under control of strict policy, it allows some services to run with the context of their clients, behaving as their client.

: CLIENT

January 31th 2019 embedded security, case of AGL 20

Links

● Doc: http://docs.automotivelinux.org/● Wiki: https://wiki.automotivelinux.org/● More: https://iot.bzh/en/publications

January 31th 2019 embedded security, case of AGL 21

Overview of LSM SMACK

January 31th 2019 embedded security, case of AGL 22

Short overview

● The author of Smack is mainly Casey Schaufler.● In Linux since kernel 2 6 25 – 17 April 2008 – as a

LSM (Linux Security Module)● Use extended file attributes to store data related to

files (like SELinux).● Controlled via a filesystem interface: smackfs.● Controls accesses of processes to files, IPC, sockets

and processes (ptrace, signals, ...).● Controls CIPSO labelled IPV4 packets● Integrated in systemd

January 31th 2019 embedded security, case of AGL 23

The Smack rules

● Smack's rules have 3 items:

– the subject's label

– the object's label

– the access

System User rwx

This rule tells to allow read, write and execute access to objects labeled User

for the processes labeled System.

What are labels? What are subjects? What are objects? How to set?

Simple !!!

January 31th 2019 embedded security, case of AGL 24

The Smack vocabulary● Labels are just text (of valid ASCII characters) without any

special meaning: they are compared to equality (case sensitive: a≠A).

● Subjects are running processes: any running process has a smack label.

● Objects are files, IPC, sockets, processes.● The label of a running process is called its security

context.

– Commands id, ps (option -Z or -M), ls (option -Z) are prompting contexts processes and files.

● The grantables access modes are: read (r), write (w), execute (x), append (a), lock (l), transmute (t), bringup (b).

January 31th 2019 embedded security, case of AGL 25

Setting Smack

How to set context? You can't! Except if you have the capability CAP_MAC_ADMIN.

# chsmack --access label file# echo -n label > /proc/$$/attr/current

# echo “subject object rwt” > /sys/fs/smackfs/load-self2# echo “subject object rwt” > /sys/fs/smackfs/load2

# echo “subject object rwt” | smackload

How to set rules? You can only reduce accesses for the current thread (inherited by cloning). But if you have the capability CAP_MAC_ADMIN, you can change all rules.

January 31th 2019 embedded security, case of AGL 26

Evolutions of Smack

● The author of Smack is mainly Casey Schaufler.● In Linux since kernel 2 6 25 – 17 April 2008 – as a LSM (Linux

Security Module)● Evoluting since this first days.

– Lock access mode (kernel 3.13)

– Support for multi-rule write to load2 and change-rule (kernel 3.12)

– Maximum value for CIPSO category change from 63 to 184 (kernel 3.12)

– Longer Smack labels (24->255) and recursive transmute (kernel 3,5)

– Transmute access mode (kernel 2.6.38)

– Bringup mode

– Netlabel filtering

January 31th 2019 embedded security, case of AGL 27

Smack links

● Kernel doc: https://www.kernel.org/doc/html/latest/admin-guide/LSM/Smack.html

● User space tools: https://github.com/smack-team/smack

January 31th 2019 embedded security, case of AGL 28

Overview of CYNAGORA permission database

January 31th 2019 embedded security, case of AGL 29

cynagora

● Cynagora is a permission database● Cynagora is a recent evolution of the

permission database named cynara

– Cynara was introduced in 2014 by Samsung for Tizen’s management of permissions

● It was a response to the insane growth of smack rules

– Was introduced as an alternative to Polkit that was to slow and not weel suited for tizen

– This defines Tizen 3 versus previous Tizens

January 31th 2019 embedded security, case of AGL 30

The cynagora rules

client session user permission

DENIED

GRANTED

OTHER (agents ...)

● The client is the requesting process identified by its Smack label● The session is supposed to identify the one session of the client● The user is the requesting user as identified by DAC● The permission is the permission that is tested

● Cynagora includes the expirations and caching

The 4-uple of values is checked

client, session, user and permission are text strings

January 31th 2019 embedded security, case of AGL 31

cynagora

low-can

cynagora

HVAC The application HVAC runs with security label User::App::HVAC

Request cynagora authorisation for User::App::HVAC PID UID PERMor if known User::App::HVAC SESSION-ID USER-ID PERM

The low-can service get the credentials of its client usinggetsockopt (SO_PEERCRED & SO_PEERSEC)

Request issued over UNIX Domain Socket

The server cynagora checks whether a rule allows the request

Issue with NAND memory (limited write cycle) => specific optimizations

cache

Caching is possible to avoid request

(getsockopt is a C function)

January 31th 2019 embedded security, case of AGL 32

cynagora

...

cynagora

agent

For some queries, the server cynagora may ask an “agent” to give or not the authorization

agentagentagent

Example 1An agent can ask the user

Session manager

Example 2An agent can ask the session manager

The application The application HVACHVAC requires permission to change requires permission to change temperature.temperature.

Do you accept?Do you accept?

Yes foreverYes forever Yes nowYes now Not nowNot now NeverNever

A t t e n t i o nA t t e n t i o n

January 31th 2019 embedded security, case of AGL 33

Cynara, comparison

January 31th 2019 embedded security, case of AGL 34

Cynagora, comparison

low-can

cynagora

HVAC

cache

agent

January 31th 2019 embedded security, case of AGL 35

Integration with DBus

● Samsung integrated cynara in Dbus. AGL use a patched version of DBUS (1.12.10 for AGL and 1.10.6 for tizen where current development is 1.13.6)

– Includes asynchronous cynara checks

– Will not enter upstream● Integration in Dbus configuration files● Cynagora is integrated through a cynara

compatibility library

January 31th 2019 embedded security, case of AGL 36

Cynagora & cynara links

● Cynagora

– Repository: https://git.automotivelinux.org/src/cynagora/

● Cynara

– Introduction: https://wiki.tizen.org/Security:Cynara

– Github: https://github.com/Samsung/cynara

– DBUS AGL version: https://git.automotivelinux.org/AGL/meta-agl/tree/meta-security/recipes-core/dbus-cynara

January 31th 2019 embedded security, case of AGL 37

Overview of AGL binder

January 31th 2019 embedded security, case of AGL 38

Connecting micro-services

SERV

C

SERV

D

SERV

B

APP

A

● The connection between micro-services (and/or applications) is a detail that must be abstract to developers

● The framework knows how to connect applications and services

● Common programming model● Its name: afb-daemon

January 31th 2019 embedded security, case of AGL 39

Programming model

monitor/get({“verbosity”: “monitor”})

Example: a call to get the verbosity level of API monitor

The api (or service)

The verb (or method) of the api

The request arguments is any JSON value

Example: curl invocation

$ curl -H ‘x-afb-token: HELLO’ \ localhost:1056/api/monitor/get?verbosity=monitor

Example: javascript invocation

afb.call(‘monitor/get’, {‘verbosity’: ‘monitor’}).then(gotapis);

Example: C binding invocation

wrap_json_pack(&req, “{ss}”, “verbosity”, “monitor”);afb_api_call(myapi, “monitor”, “get”, req, gotpis, NULL);

The reply is a JSON value

{ "verbosity": { "monitor":"info" }}

January 31th 2019 embedded security, case of AGL 40

Programming model

● Advantages:

– Using HTTP(s) and WS(s), the model crosses firewalls

– JSON data as argument or result introduce flexibility, reliable portability and wide language binding

– Agnostic about programming language● Drawbacks:

– Need for agreement on names of API

– JSON (de)serialisation

January 31th 2019 embedded security, case of AGL 41

Use case of the binder

cloudAPPLI SERVICE

BINDERA

BINDER

BAPPLI

BINDERC

BINDING

BINDERD

BINDING

Connected carMaster ECU

Other ECU

HTTPS+WSS/TCP HTTPS+WSS/TCP

WS/UDS

WSS/TCP

WS: WebSocketWSS: WS SecuredUDS: Unix Domain Socket

January 31th 2019 embedded security, case of AGL 42

Binder vocabulary

● Binder: the process afb-daemon● Binding: a binary loaded by the binder that

implements one or more apis● Api: a set of verbs belonging to the same

name and implemented by only one binding● Verb: A callable endpoint, accept arguments,

return result, can be protected● Transparency or “shadow api”: fact that a

remote api is accessed like a local api

January 31th 2019 embedded security, case of AGL 43

Feature of the AGL binder

● Connection of services and applications together (UDS, WS/UDS, WS/TCP, HTTP, linked)

● High level flexible RPC mechanism (hide connections)● Framework for event signaling● Security and permissions facilities (Smack + cynagora)● HTTP server managing OPA and WebSockets● Binary implementation of services (aka “binding”)● Management of client sessions and contexts● Debugging, monitoring and supervision

RPC: Remote Procedure CallOPA: One Page Application

January 31th 2019 embedded security, case of AGL 44

Protection of binder

● Connections can require a secret token● Execution of verbs of APIs can be protected

– By permissions

– By Level Of Assurance

– By secret token● Binder executes cynagora checks● Binder controls internal execution, recovering from

failure in bindings● Automatic reconnection after server failures

January 31th 2019 embedded security, case of AGL 45

Binder/Binding model●Binder–Container process

●Loads bindings (binaries currently but also possibly scripts if needed in future -js?-)

–Transport●Makes the transport abstract–Security–Standardized high level Sync/Async API–Standardized high level event model–Expose API through HTTP or WebSocket

● Protected by token●Binding–One or more API published through binder–Provided as:

● A native library weakly coupled (threading allowed)● A stub to a remote service

APPLICATION

BINDERafb-daemon

API Z

BINDERafb-daemon API Z

A

B

API X

API Y

Application and its binder runs the same security context

This binder implements two APIs: X and Y

This API is remote or imported

This binding implements only one API: Z

Implicit API/WS RPC

The binder exports the API Z

Explicit HTTP+WS link

January 31th 2019 embedded security, case of AGL 46

Binder’s connections

● Binders accept 2 kind of incoming connections

– Common HTTP+WS: this connection is the common one (HTTP and/or WebSocket).

● It acts as an HTTP server that accept upgrade to a websocket for it api “pod”.

● It exports all the API known by the binder● It manages sessions and tokens

– Specific API/WS: this connection is specific to an API (API over special WebSocket).

● Only one API● Doesn’t manage session or tokens

January 31th 2019 embedded security, case of AGL 47

Connection of apis: API/WS

● The binder connects apis using point to point connections

● Compared to a bus, advantages are:

– less contention (pressure),

– no mediator (security and efficiency)

BINDERafb-daemon

API X

API Y

API Z

BINDERafb-daemon

API Z

API Y

BINDERafb-daemon

API Y

January 31th 2019 embedded security, case of AGL 48

Libafbwsc & afb-client-demo

● The binder provides a client library to connect to binders either by their WS/HTTP pod or by their API/WS pod

● Some component of AGL use that library● A sample program demonstrates the use of

that library: afb-client-demo. It can be used to connect to binders during development.

● Still need a true documentation.

January 31th 2019 embedded security, case of AGL 49

Use of binder

● Services gain high benefits to be integrated by binders, they get for free:

– High level programming model with events

– Connectivity managed

– Security enforced● Applications have the choice to either

– Connect to a binder that is connected to service

– Connect directly to the services it uses through libafbwsc but in this case integration with the whole system may encounter glitches

January 31th 2019 embedded security, case of AGL 50

UML view

: APPLICATION

: BINDER

: BINDING

: BINDING

: BINDING

: SERVICE

HTTP WebSocket

: BINDER

: BINDING

This link can be either DBus or UDS or WebSocket (on LAN or WAN)

Native link to services is not forbiden. A library allows to connect to Binder's services

A service can be implemented on top of binder's framework

security context APPLICATION

security context SERVICE

January 31th 2019 embedded security, case of AGL 51

Monitoring

January 31th 2019 embedded security, case of AGL 52

Supervision

● Monitor allows a client to debug and introspect itself

● Supervision is the extension that allows to inspect all binders, APIs and sessions

● Binders connect to the supervisor

● Access to supervisor are restricted

● Capabilities of supervisor are reduced on cars

BINDER

BINDER

BIN

DER

BIN

DE

R

BIN

DE

R

BIN

DE

R

BINDER

SUPERVISOR

January 31th 2019 embedded security, case of AGL 54

Overview of

bindings and APIs

January 31th 2019 embedded security, case of AGL 55

What are bindings?

● Generally one binding implement one API

– It exports a set of verbs that can be called● Bindings are loaded by the binder at start● Bindings receive request for verbs and should reply to it● Bindings can call verbs of other APIs for themselves or

for their client● Bindings are not linked to the binder, it can be executed

in other context or other binders● Currently bindings are binary libraries written in C/C++

January 31th 2019 embedded security, case of AGL 56

Binding and APIs

● Bindings version 3 available since Funky Flounder are able to define 0, 1 or many APIs:

– 0: No public interface, useful to create in binder applications

– 1: The standard case, static declaration preferred

– 2+: This rare case is implemented by the controller and used by 4A (AGL Advanced Audio Architecture)

● New APIs can be created at any time (if needed)

January 31th 2019 embedded security, case of AGL 57

Link to OpenAPI

● OpenAPI is a linux foundation effort intended to standardizing on how REST APIs are described

● APIs can be described using a subset of OpenAPI v3 specification

● A generator can produce the skeleton of a binding based on its openAPI description

● The binder produce an openAPI compatible description of its API through call monitor/get({“api”:true})

● This is useful if you use swagger or compatible tool

January 31th 2019 embedded security, case of AGL 58

The 3 main states

● The binder defines 3 main steps that the binding must respect and conform:

– PREINIT: The binder discovers the bindings and loads it.● No call to APIs is possible.● Can declare new APIs● Can explicit their class dependencies (provide/require)

– INIT: All the bindings are loaded, the binder call the initialization function (if any) of all API.

● Calls other APIs is possible● Can explicit their API dependencies (require)

– RUNNING: All initialization successful

January 31th 2019 embedded security, case of AGL 59

Weak dependency

● Bindings are not linked to any binder library● Bindings receive the binder entry points like virtual function

table of C++● Bindings declare the version of the binder API it uses● Advantages:

– Binder can adapt to the version of the binding

– A same binding binary can be used by the binder or by programs implementing binder interfaces

: BINDING : BINDER

binding's interface

binder's interface

: BINDING SOME APPLICATION

binding's interface

binder's interface

January 31th 2019 embedded security, case of AGL 60

Example: hello world

1 #define AFB_BINDING_VERSION 3 2 #include <afb/afb-binding.h> 3 4 void hello(afb_req_t req) 5 { 6 AFB_REQ_DEBUG(req, "hello world"); 7 afb_req_reply(req, NULL, NULL, "hello world"); 8 } 9 10 const afb_verb_t verbs[] = { 11 { .verb="hello", .callback=hello }, 12 { .verb=NULL } 13 }; 14 15 const afb_binding_t afbBindingExport = { 16 .api = "tuto-1", 17 .verbs = verbs 18 };

static inlinevoid afb_req_reply(

afb_req_t *req,json_object *obj,const char *error,const char *info)

{req->itf->reply(req,

obj, error, info);}

January 31th 2019 embedded security, case of AGL 61

Managing events

● APIs can create events by name

– These are in fact handles to push events

– Ex: the api telephony creates an event incomingCall that is finally named event telephony/incomingCall

● APIs can push data for an event

– Pushing means send the data tagged by the event name to all listeners

● APIs control how its clients subscribe to its events by adding or removing it to the list of listeners

● APIs can also listen for events

January 31th 2019 embedded security, case of AGL 62

Example: event knock

1 afb_event_t evt_knock; 2 3 void knock(afb_req_t req) 4 { 5 afb_event_push(evt_knock, json_object_get(afb_req_json(req))); 6 afb_req_reply(req, NULL, NULL, NULL); 7 } 8 9 void listen(afb_req_t req) 10 { 11 if (json_object_get_boolean(afb_req_json(req))) 12 afb_req_subscribe(req, evt_knock); 13 else 14 afb_req_unsubscribe(req, evt_knock); 15 afb_req_reply(req, NULL, NULL, NULL); 16 } 17 18 void init(afb_api_t api) 19 { 20 evt_knock = afb_api_make_event(api, "knock"); 21 }

January 31th 2019 embedded security, case of AGL 63

Overview of

WidgetsWGT

January 31th 2019 embedded security, case of AGL 64

AGL development model

core

system

user

AGL profile sourceyocto generates the

core image

yocto generatesthe SDK

Applicationsources

WGTAGL SDK

Compilewith SDK

widget

WGT

January 31th 2019 embedded security, case of AGL 65

Packaging applications

Developer team

Configuration fileconfig.xml

1. Developer team produces the application or service

2. Developer team describes its

product and its requirements

WGT

January 31th 2019 embedded security, case of AGL 66

Security manifest: config.xml<?xml version="1.0" encoding="UTF-8"?><widget xmlns="http://www.w3.org/ns/widgets" id="org.openstreetmap.agl.pushviews" version="1.0.1"> <name>Push street views</name> <icon src="pushviews.png"/> <content src="index.html" type="text/html"/> <description>Pushes camera views to openstreetmap</description> <author>Open Street Map</author> <license>GPL</license> <feature name="urn:AGL:widget:required-api"> <param name="gps" value="ws" /> <param name="sensors" value="ws" /> <param name="camera" value="ws" /> <param name="pushviews:https://agl.openstreetmap.org/cloud/pushviews" value="cloud" /> </feature>…

WGT

January 31th 2019 embedded security, case of AGL 67

Security manifest: config.xml

… <feature name="urn:AGL:widget:required-permission"> <param name="urn:AGL:permission:gps:public:read" value="required" /> <param name="urn:AGL:permission:sensors:public:read" value="required" /> <param name="urn:AGL:permission:camera:public:take:front" value="required" /> <param name="urn:AGL:permission:camera:public:take:rear" value="optional" /> </feature></widget>

WGT

January 31th 2019 embedded security, case of AGL 68

Packaging applications

Developer team

signed content

3. Developer team signs its product

WGT

January 31th 2019 embedded security, case of AGL 69

Packaging applications

signed content

Authority 1Authority 2

4. Authorities sign the product

WGT

That authority adds a key that will unlock special permissions

January 31th 2019 embedded security, case of AGL 70

Packaging applications

signed content

WGTWGT

packaged content

5. zip the product, its config and its signatures

WGT

January 31th 2019 embedded security, case of AGL 71

Packaging applications

signed content

WGTWGT

packaged content

config.xml

This signature opens permissions to the widget

WGT

January 31th 2019 embedded security, case of AGL 72

Preferred structure of widgets

/

bin

lib

etc

lang

htdocs

en

jp

libexec

Native executables

Local libraries of executables (RPATH)

Bindings

Configuration files

...

Internationalization

index.html

...

config.xml

Served HTTP files

author.sig

...

Manifest files

January 31th 2019 embedded security, case of AGL 73

links

● Widgets are defined by W3C: https://www.w3.org/TR/widgets/

● How they are signed is also defined by W3C: https://www.w3.org/TR/widgets-digsig/

● Implementation in AGL: https://git.automotivelinux.org/src/app-framework-main/

WGTWGT

January 31th 2019 embedded security, case of AGL 74

Overview of AGL

framework

January 31th 2019 embedded security, case of AGL 75

History of the framework

Tizen 3

Ostro

AGL

June 2

015

Marc

h 2015

Nov. 2015

First tizen 3 security

release

AGL spec 1.0 may 28th

Dec. 2

016

Integration to AGL

Start of refiting the framework

Introduction of the binder

synchronization

Marc

h 2017

Oct. 2

017

Integration to systemD

Integration to systemD with users

January 31th 2019 embedded security, case of AGL 76

Cryptographic check of permission

● PKI model for signing authority● Public keys distribution● Use cryptography to compute the maximal

set of permission for an installed app● Records and check publisher and owner

certificates● Link file digests with IMA

public

partner

platform

system

Any Tiers Authorized Tiers Confident Tiers Manufacturer

Can't use sensitive features

Can access some sensitive features

Can access many sensitive features

Can access ALL features

optional

January 31th 2019 embedded security, case of AGL 77

Definition of permissions

urn:AGL:permission:<api>:<level>:<hierarchical-name>

The API providing the permission. If empty (or

starting with @) then it is a transverse permission

not linked to an API.

One of the values:— system

— platform— partner

— publisher— owner— public

Colon separated names possibly defining hierarchies of permissions

Cryptography protection

Examples:● urn:AGL:permission::public:no-htdocs● urn:AGL:permission:afm:system:widget:install

January 31th 2019 embedded security, case of AGL 78

Figure of the framework

AGL framework

WGT

WGT

Security Context

DB of apps=

Widget’s files + systemd units

systemd

service

APPLICATION

or

January 31th 2019 embedded security, case of AGL 79

Figure of the framework

● Installation & uninstallation:

– Manages right: smack + cynagora + groups

– Isolate● Managing processes with systemd

– Natural integration with boot sequence

– Socket activation of services

– Integration of cgroups and many other advanced topics for free

January 31th 2019 embedded security, case of AGL 80

config.xml

Integration with systemd

/etc/afm/afm-unit.conf

WGT

WGT

json

Mustacheengine

Unitsdescription

*.service *.socket ...

temporarydata

Unit installer

January 31th 2019 embedded security, case of AGL 81

Internal widget config

<feature name="urn:AGL:widget:required-permission"> <param name="urn:AGL:permission:real-time" value="required" /> <param name="urn:AGL:permission:syscall:*" value="required" /> </feature>

"required-permission":{ "urn:AGL:permission:real-time":{ "name":"urn:AGL:permission:real-time", "value":"required" }, "urn:AGL:permission:syscall:*":{ "name":"urn:AGL:permission:syscall:*", "value":"required" }}

EXTRACT OF CONFIG.XML

INTERNAL JSON

Internal transformduring installation

January 31th 2019 embedded security, case of AGL 82

Mustache templating

Hello {{name}}You have just won {{value}} dollars!{{#in_ca}}Well, {{taxed_value}} dollars, after taxes.{{/in_ca}}

Hello ChrisYou have just won 10000 dollars!Well, 6000.0 dollars, after taxes.

{ "name": "Chris", "value": 10000, "taxed_value": 10000 - (10000 * 0.4), "in_ca": true}

TEMPLATE DATA

PRODUCT

Details: https://mustache.github.io/https://gitlab.com/jobol/mustach

January 31th 2019 embedded security, case of AGL 83

Example of afm-unit.conf

[Service]SmackProcessLabel=User::App::{{:id}}User=%i

CapabilityBoundingSet=AmbientCapabilities=

Slice=user-unlimited-%i.slice

{{#required-permission}} {{#urn:AGL:permission::public:display}} SupplementaryGroups=display {{/urn:AGL:permission::public:display}}{{/required-permission}}

Conditionnal group

UID of the useris the parameter

Setting of SMACK

January 31th 2019 embedded security, case of AGL 84

Security Context

afb-daemon

Internal daemons

afm-system-daemon

Bindings

application

systemd

afm-user-daemon(legacy)

dbus

ws-client ws-client

USER LAND

SYSTEM LAND

afm-util

transitionnal

transitionnal

January 31th 2019 embedded security, case of AGL 85

links

● Repo: https://git.automotivelinux.org/src/app-framework-main/

● Doc: http://docs.automotivelinux.org/docs/apis_services/en/dev/

● Localuser: https://github.com/iotbzh/nss-localuser

January 31th 2019 embedded security, case of AGL 86

Overview of user

management

January 31th 2019 embedded security, case of AGL 87

User identity handling

● Default users exist: agl-driver and agl-passenger● Existing several ways of authenticating users

– Key RF

– Phone

– Gesture

– ...● Provide dynamic allocation of uids for authenticated users● Use uids to ensure privacy of users and Smack for privacy

of applications● Link identity with the Oauth2 service to allow federation

January 31th 2019 embedded security, case of AGL 88

Identity workflow

PAM activation

✔ Plugable Authentication Module✔ Standard✔ Highly configurable✔ Modular design

✔ Face recognition✔ Voice identification✔ Password

1. initiate authentication

2. start user session

User identity service

USER SESSION

Cloudidentity

User services

User applications3. sync

January 31th 2019 embedded security, case of AGL 89

Identity service

User identity service

USER SESSION

Cloudidentity

User services

User applications

Userdata

● Manage user data● By application● Globally

● Manage synchronisation and caching● Provide OpenId negociation

January 31th 2019 embedded security, case of AGL 90

Launching application

USER SESSION

afm-system-daemon systemd

Home screen User applications

UID of the clientis the parameter

January 31th 2019 embedded security, case of AGL 91

Overview of AGL

anywhere for anyone

January 31th 2019 embedded security, case of AGL 92

Acces control by token

● The application framework (APPFW) launches applications, services and binders. It allocates security tokens.

● When a client connects to its binder, it presents its security token.

● The binder queries the APPFW to check whether the security token is valid or not.

● The security token management could be delegated by the APPFW to a specialized service (design).

● Tokens should include:

– Expiration

– Credentials

– Abstract identity

January 31th 2019 embedded security, case of AGL 93

Local access

BINDER23

AGL domain (CAR) LOCAL“HOME SCREEN”

AGLAPPFW

APP23

①②

(1) Ask to launch APP 23(2) Launch APP 23(3) Ask its token (check of PID, SMACK, UID)(4) Connect to the binder with its token(5) Check token validity

January 31th 2019 embedded security, case of AGL 94

Remote application

AGLBINDER

CLIENTBROWSER

APPLICATION

HTTPSWSS(tcp) tcp

uds

REVERSEPROXY

AGL domain (CAR)internet

Remote client can run on any OS: MAC OS, Windows, Android, Linux, ...

January 31th 2019 embedded security, case of AGL 95

Remote access

BINDER23

CLIENTBROWSER

APP 23

REVERSEPROXY

AGL domain (CAR)internet REMOTE“HOME”CLIENT

BROWSER“HOME”

AGLAPPFW

(1) Ask to launch APP 23(2) Returns the URL of the BINDER for APP 23 and its token (in the URI?)(3) Connect to the binder with its token(4) Check token validity

January 31th 2019 embedded security, case of AGL 96

With redirect

BINDER23

CLIENTBROWSER

APP 23

REVERSEPROXY

AGL domain (CAR)internet

AGLAPPFW

④ ②

(1) Connect to the binder with invalid token(2) Check token validity(3) Return redirect(4) Redirected query (sequel depend on policies)

January 31th 2019 embedded security, case of AGL 97

Examples of AGL works

January 31th 2019 embedded security, case of AGL 98

Pure HTML5 application

internetWeb Browser

BINDER

A

HTTPS+WSS/TCP

Awebruntime

(local)

● Any web browser, local or remote access the binder

● The binder acts as a web server OPA compliant

● The binder allows connection to AGL services

● The file AFB.js implement a simple connection to AGL APIs in javascript

Same security context

Data of the application

Access to services

OPA: One Page Application

January 31th 2019 embedded security, case of AGL 99

Using AFB.js

1 var loc = document.location; 2 var args = new URLSearchParams(loc.search.substring(1)); 3 var afb = new AFB({ 4 host: loc.hostname + ':' + loc.port, 5 token: args.get("x-afb-token") || args.get("token") || "HELLO" 6 }); 7 var ws = new afb.ws(onopen, onabort); 8 9 function onopen() {10 ws.onclose = onabort;11 ws.onevent("*", onevent);12 ws.call("api/verb", { arg1: true, arg2: 'data' }).then(13 onsuccess, onerror);14 }

January 31th 2019 embedded security, case of AGL 100

HTML5 application extended

Web Browser

A

HTTPS+WSS/TCP

Awebruntime

(local)

● The application includes a binding

– Binary acceleration

– Confidential code

– Access to hardware● The API(s) of the

binding aren’t exported● Only the application

access the binding API

Access to servicesBINDERAPI

January 31th 2019 embedded security, case of AGL 101

Using a binding

<?xml version="1.0" encoding="UTF-8"?><widget xmlns="http://www.w3.org/ns/widgets" id="exthtml5" version="1.0"> <name>Extended HTML5</name> <icon src="icon.png"/> <description>Example of application with binding</description> <author>me</author> <license>MIT</license> <content src="index.html" type="text/html"/> <feature name="urn:AGL:widget:required-binding"> <param name="libexec/binding-exthtml5.so" value="local" /> </feature></widget>

January 31th 2019 embedded security, case of AGL 102

General service

● Exporting an API is essential to building a system

● The exported API can be protected by permissions

S

Access to other

services

BINDER API

Exported API

Data of the service

January 31th 2019 embedded security, case of AGL 103

Native application

BINDER

ANative

● Any web browser, local or remote access the binder

● The binder acts as a web server OPA compliant

● The binder allows connection to AGL services

● The file AFB.js implement a simple connection to AGL APIs in javascript

Access to services

HTTP+WS/TCP

January 31th 2019 embedded security, case of AGL 104

links

● AFB.js: https://git.automotivelinux.org/src/app-framework-binder/tree/test/AFB.js

● QafbWebsocketClient: https://git.automotivelinux.org/apps/app-afb-helpers-submodule/

January 31th 2019 embedded security, case of AGL 105

Managing Level Of

Assurance

January 31th 2019 embedded security, case of AGL 106

LOA within bindings

● The binder provide by client and by API a value called LOA (for Level Of Assurance) (from 0 to 7)

● Standard meaning of LOA are:

– Level of Assurance 1: Little or no confidence in the asserted identity’s validity.

– Level of Assurance 2: Some confidence in the asserted identity’s validity.

– Level of Assurance 3: High confidence in the asserted identity’s validity.

– Level of Assurance 4: Very high confidence in the asserted identity’s validity.● The binding implementation manages that value using the verb afb_req_session_set_LOA

● The LOA can be checked as a requirement before an API’s verb is called

● Binding implementations are allowed to change the meaning of the LOA level for their own purpose

January 31th 2019 embedded security, case of AGL 107

LOA example

AFB_SESSION_LOA_1

afb_auth_Permission

void login(afb_req_t *req) {

afb_req_session_set_LOA(req, 1); afb_req_success(req, NULL, NULL);

}

afb_auth_t autlogin = { .type=afb_auth_Permission, .text=”urn:AGL:permission:...” };

afb_verb_t verbs[] = { { .verb=”login”, .callback=login, .auth=&autlogin }, { .verb=”action”, .callback=action,

.session=AFB_SESSION_LOA_1 },

{ .verb=NULL }

};

January 31th 2019 embedded security, case of AGL 109

Design philosophy

KEEP IT SIMPLE

and Flying !