Challenges and Possibilities for Safe and Secure ASN.1 Encoders and - - PowerPoint PPT Presentation

challenges and possibilities for safe and secure asn 1
SMART_READER_LITE
LIVE PREVIEW

Challenges and Possibilities for Safe and Secure ASN.1 Encoders and - - PowerPoint PPT Presentation

Challenges and Possibilities for Safe and Secure ASN.1 Encoders and Decoders Mark Tullsen Galois, Inc. LangSec, May 2018 Mark Tullsen (Galois, Inc.) ASN.1 Challenges and Possibilities LangSec, May 2018 1 / 32 Outline Introduction 1 Five


slide-1
SLIDE 1

Challenges and Possibilities for Safe and Secure ASN.1 Encoders and Decoders

Mark Tullsen

Galois, Inc.

LangSec, May 2018

Mark Tullsen (Galois, Inc.) ASN.1 Challenges and Possibilities LangSec, May 2018 1 / 32

slide-2
SLIDE 2

Outline

1

Introduction

2

Five Things to Like About ASN.1

3

Obstacles to Secure ASN.1

4

Approaches to Secure ASN.1 Encoders/Decoders

5

Galois’ Current & Future Work

Mark Tullsen (Galois, Inc.) ASN.1 Challenges and Possibilities LangSec, May 2018 2 / 32

slide-3
SLIDE 3

1

Introduction

2

Five Things to Like About ASN.1

3

Obstacles to Secure ASN.1

4

Approaches to Secure ASN.1 Encoders/Decoders

5

Galois’ Current & Future Work

Mark Tullsen (Galois, Inc.) ASN.1 Challenges and Possibilities LangSec, May 2018 3 / 32

slide-4
SLIDE 4

About This Talk

Primarily a "position paper" : Secure ASN.1 IMHO For technical details, see our CAV 2018 paper

Formal Verification of a Vehicle-to-Vehicle (V2V) Messaging System

Mark Tullsen (Galois, Inc.) ASN.1 Challenges and Possibilities LangSec, May 2018 4 / 32

slide-5
SLIDE 5

What is ASN.1?

ASN.1 is not

a format a single specification a library (that we can implement once)

ASN.1 is

a language by which we define hundreds of protocols and data-formats!

Mark Tullsen (Galois, Inc.) ASN.1 Challenges and Possibilities LangSec, May 2018 5 / 32

slide-6
SLIDE 6

The Importance (& Risks) of ASN.1

ASN.1 pervasive Decoding ASN.1-defined messages: definitely on the attack surface

Mark Tullsen (Galois, Inc.) ASN.1 Challenges and Possibilities LangSec, May 2018 6 / 32

slide-7
SLIDE 7

1

Introduction

2

Five Things to Like About ASN.1

3

Obstacles to Secure ASN.1

4

Approaches to Secure ASN.1 Encoders/Decoders

5

Galois’ Current & Future Work

Mark Tullsen (Galois, Inc.) ASN.1 Challenges and Possibilities LangSec, May 2018 7 / 32

slide-8
SLIDE 8

ASN.1 is Abstract

ASN.1 does not limit us to a single implementation language nor to a single de facto representation of the "abstract" values

T ::= SEQUENCE (SIZE(1..4)) OF INTEGER

One may have different concrete values/representations:

typedef int T[4]; // probably not if SIZE(1..10000) typedef int *T; // length elsewhere , or special encode of "last" typedef struct node *T; // i.e., a linked-list

Mark Tullsen (Galois, Inc.) ASN.1 Challenges and Possibilities LangSec, May 2018 8 / 32

slide-9
SLIDE 9

ASN.1 is Highly Expressive (for describing data)

ASN.1 provides an extensive and powerful set of types and constraints for describing data (beyond typical programming languages!)

Mark Tullsen (Galois, Inc.) ASN.1 Challenges and Possibilities LangSec, May 2018 9 / 32

slide-10
SLIDE 10

ASN.1 is Highly Expressive (for describing data)

ASN.1 provides an extensive and powerful set of types and constraints for describing data (beyond typical programming languages!)

Address::= SEQUENCE { street VisibleString (SIZE (5 .. 50)) OPTIONAL , city VisibleString (SIZE (2..30)), state VisibleString (SIZE(2) ^ FROM ("A".."Z")), zipCode NumericString (SIZE(5 | 9)) } ListOfItems ::= SEQUENCE (SIZE (1..100)) OF Item Item ::= SEQUENCE { itemCode INTEGER (1..99999), power INTEGER (110 | 220), deliveryTime INTEGER (8..12 | 14..19), isTaxable BOOLEAN }

Mark Tullsen (Galois, Inc.) ASN.1 Challenges and Possibilities LangSec, May 2018 9 / 32

slide-11
SLIDE 11

ASN.1 is Compositional

I.e., we can compose small data definitions to create larger ones. Has a real module system. Can refer to modules outside the current system. Can embed data of undetermined types, safely and sanely.

With Information Objects . . . even more elegantly

Mark Tullsen (Galois, Inc.) ASN.1 Challenges and Possibilities LangSec, May 2018 10 / 32

slide-12
SLIDE 12

ASN.1 is Versatile: Multiple Encoding Schemes

Allows for a variety of encoding methods, each specified separately from the definition of abstract values. E.g., Basic Encoding Rules (BER), Distinguished Encoding Rules (DER), XML Encoding Rules (XER), Canonical XML Encoding Rules (CXER), Packed Encoding Rules (PER, unaligned: UPER, canonical: CPER, canonical unaligned: CUPER), Octet Encoding Rules (OER, canonical: COER), etc.

Mark Tullsen (Galois, Inc.) ASN.1 Challenges and Possibilities LangSec, May 2018 11 / 32

slide-13
SLIDE 13

ASN.1 is Versatile: Multiple Encoding Schemes

Allows for a variety of encoding methods, each specified separately from the definition of abstract values. E.g., Basic Encoding Rules (BER), Distinguished Encoding Rules (DER), XML Encoding Rules (XER), Canonical XML Encoding Rules (CXER), Packed Encoding Rules (PER, unaligned: UPER, canonical: CPER, canonical unaligned: CUPER), Octet Encoding Rules (OER, canonical: COER), etc. Self-describing: BER, DER, etc. Highly bit-efficient: *OER, *PER (must know ASN.1 type to decode) Canonical signifies that a given value has only a single valid encoding

E.g., for X.509, DER is used (canonical)

Mark Tullsen (Galois, Inc.) ASN.1 Challenges and Possibilities LangSec, May 2018 11 / 32

slide-14
SLIDE 14

ASN.1 is Extensible: Features for Protocol Evolution

Provides mechanisms for extensibility to allow protocols and formats to evolve gracefully.

MyCoffeeShopMenu ::= SEQUENCE { coffee Price, tea Price, ...!1,

  • - extensible , exception -marker!

[[ sandwich Price,

  • - Version2

dessert Price ]] }

Mark Tullsen (Galois, Inc.) ASN.1 Challenges and Possibilities LangSec, May 2018 12 / 32

slide-15
SLIDE 15

ASN.1 is Extensible: Features for Protocol Evolution

Provides mechanisms for extensibility to allow protocols and formats to evolve gracefully.

MyCoffeeShopMenu ::= SEQUENCE { coffee Price, tea Price, ...!1,

  • - extensible , exception -marker!

[[ sandwich Price,

  • - Version2

dessert Price ]] }

This data specification

marked as extensible has evolved

The bits on the wire indicate if the data is in the base or extension

Thus, Version1 encoders/decoders work on Version2 data.

Mark Tullsen (Galois, Inc.) ASN.1 Challenges and Possibilities LangSec, May 2018 12 / 32

slide-16
SLIDE 16

1

Introduction

2

Five Things to Like About ASN.1

3

Obstacles to Secure ASN.1

4

Approaches to Secure ASN.1 Encoders/Decoders

5

Galois’ Current & Future Work

Mark Tullsen (Galois, Inc.) ASN.1 Challenges and Possibilities LangSec, May 2018 13 / 32

slide-17
SLIDE 17

Obstacles to Secure ASN.1

Following Frederick Brooks—and Aristotle—in the use of these terms: Obstacles, Essential (intrinsic, "of the essence") Obstacles, Accidental (historical, poor design, etc.)

Mark Tullsen (Galois, Inc.) ASN.1 Challenges and Possibilities LangSec, May 2018 14 / 32

slide-18
SLIDE 18

Essential Obstacles

The Five Things to Like each creates some degree of

complexity in the ASN.1 definition language itself non-trivial learning curve for users and implementers complexity for an ASN.1 compiler complexity in (and multiplicity of) the encode/decode routines etc.

Thus, a large effort to fully support the language

Unsurprisingly, fully compliant compilers are expensive & proprietary

There will be a loss of abstraction in the concrete types: room for errors in the interfacing code. (The cost of Things to Like 1, 2, 5.) With new & improved (bit-efficient) encoding schemes (PER, UPER, OER, etc.),

Previous—and simpler—library-based solutions inadequate Compiler that uses global knowledge and "constraint solving": recommended!

Mark Tullsen (Galois, Inc.) ASN.1 Challenges and Possibilities LangSec, May 2018 15 / 32

slide-19
SLIDE 19

Accidental Obstacles

Evolutionary artifacts

Complicate the language Force us to support old features and old specs E.g.,

explicit TAGs / AUTOMATIC TAGS newer encoding schemes that fix old ones methods to encode unknowns or parameters

Over-complexity

Information Objects Encoding scheme details

e.g., long tags vs. long lengths vs. long values Many closely related encoding schemes (is there a canonical encoding or not)

The ASN.1 Language itself

Literally thousands of grammar rules to parse the language.

Mark Tullsen (Galois, Inc.) ASN.1 Challenges and Possibilities LangSec, May 2018 16 / 32

slide-20
SLIDE 20

The Unfortunate Outcome

ASN.1’s complex and evolving language features, as well as its complex and evolving encoding schemes, together

hinder adoption increase the complexity of tools & compilers, and necessitate large and complex encoder/decoder implementations.

Mark Tullsen (Galois, Inc.) ASN.1 Challenges and Possibilities LangSec, May 2018 17 / 32

slide-21
SLIDE 21

The Unfortunate Outcome

ASN.1’s complex and evolving language features, as well as its complex and evolving encoding schemes, together

hinder adoption increase the complexity of tools & compilers, and necessitate large and complex encoder/decoder implementations.

None of which bode well for the task of creating robust & secure implementations.

Mark Tullsen (Galois, Inc.) ASN.1 Challenges and Possibilities LangSec, May 2018 17 / 32

slide-22
SLIDE 22

1

Introduction

2

Five Things to Like About ASN.1

3

Obstacles to Secure ASN.1

4

Approaches to Secure ASN.1 Encoders/Decoders

5

Galois’ Current & Future Work

Mark Tullsen (Galois, Inc.) ASN.1 Challenges and Possibilities LangSec, May 2018 18 / 32

slide-23
SLIDE 23

The Goal

. . . creating robust & secure1 encoder/decoder implementations.

1secure: absence of software flaws Mark Tullsen (Galois, Inc.) ASN.1 Challenges and Possibilities LangSec, May 2018 19 / 32

slide-24
SLIDE 24

The Goal

. . . creating robust & secure1 encoder/decoder implementations. With very high assurance.

1secure: absence of software flaws Mark Tullsen (Galois, Inc.) ASN.1 Challenges and Possibilities LangSec, May 2018 19 / 32

slide-25
SLIDE 25

The Goal

. . . creating robust & secure1 encoder/decoder implementations. With very high assurance. Provably secure?

1secure: absence of software flaws Mark Tullsen (Galois, Inc.) ASN.1 Challenges and Possibilities LangSec, May 2018 19 / 32

slide-26
SLIDE 26

The Goal

. . . creating robust & secure1 encoder/decoder implementations. With very high assurance. Provably secure? With reasonable effort?

1secure: absence of software flaws Mark Tullsen (Galois, Inc.) ASN.1 Challenges and Possibilities LangSec, May 2018 19 / 32

slide-27
SLIDE 27

Generating Good Code?

Roll your own ASN.1 encoder/decoder

Possible! Isn’t ASN.1 simple stuff: just serializing/deserializing?

Open source compilers

Limited in features and support. E.g., code definitely not optimized for clarity/verification

Commercial compilers

Objective Systems compiler "bad memory bug" Library flaws

Exploitable flaw in MS Windows library for years

Mark Tullsen (Galois, Inc.) ASN.1 Challenges and Possibilities LangSec, May 2018 20 / 32

slide-28
SLIDE 28

Generating Good Code?

Roll your own ASN.1 encoder/decoder

Possible! Isn’t ASN.1 simple stuff: just serializing/deserializing?

Open source compilers

Limited in features and support. E.g., code definitely not optimized for clarity/verification

Commercial compilers

Objective Systems compiler "bad memory bug" Library flaws

Exploitable flaw in MS Windows library for years

None of these can guarantee security.

Mark Tullsen (Galois, Inc.) ASN.1 Challenges and Possibilities LangSec, May 2018 20 / 32

slide-29
SLIDE 29

Secure Code via Testing?

Extensive testing

incomplete! intelligent, expert, human testing: good idea

"Program testing can be used to show the presence of bugs, but never to show their absence!" - Dijkstra

Mark Tullsen (Galois, Inc.) ASN.1 Challenges and Possibilities LangSec, May 2018 21 / 32

slide-30
SLIDE 30

Secure Code via Testing?

Extensive testing

incomplete! intelligent, expert, human testing: good idea

"Program testing can be used to show the presence of bugs, but never to show their absence!" - Dijkstra "Exhaustive Testing"?

Given this decode function with execution time of 1ms:

bool decode( uint64_t x, uint64_t y, uint64_t z) { .. }

Time to exhaustively test: 2 × 1047 years

Mark Tullsen (Galois, Inc.) ASN.1 Challenges and Possibilities LangSec, May 2018 21 / 32

slide-31
SLIDE 31

Secure Code by Construction

Develop a fully-compliant (open-source) ASN.1 compiler.

Make it a verified compiler

Remember to verify the libraries, ;-)

Make it certifying (generating proof of correctness/safety)

Mark Tullsen (Galois, Inc.) ASN.1 Challenges and Possibilities LangSec, May 2018 22 / 32

slide-32
SLIDE 32

Secure Code by Construction

Develop a fully-compliant (open-source) ASN.1 compiler.

Make it a verified compiler

Remember to verify the libraries, ;-)

Make it certifying (generating proof of correctness/safety)

Immensely Large Effort

Mark Tullsen (Galois, Inc.) ASN.1 Challenges and Possibilities LangSec, May 2018 22 / 32

slide-33
SLIDE 33

Secure Code by . . . Divide and Conquer? (1)

In order to reduce trusted computing base . . . Full ASN.1 to ASN.1-lite transformation tool.

Possibly remove 80% of the complexity of ASN.1 Allow for use of simpler, open-source ASN.1 tools/compilers Much of the complexity of ASN.1 "goes away" in compilation.

Mark Tullsen (Galois, Inc.) ASN.1 Challenges and Possibilities LangSec, May 2018 23 / 32

slide-34
SLIDE 34

Secure Code by . . . Divide and Conquer? (2)

Another approach to avoiding giant monolithic proofs . . . Use an Intermediate Language For Serialization (ILS)?

Just powerful enough to describe BER, DER, UPER, OER TODO: What are the key primitives and combinators needed?

spec.asn spec(uper).ils VALUES BITS spec.c

Assurance & Verification?

can verify the parts separately!

Mark Tullsen (Galois, Inc.) ASN.1 Challenges and Possibilities LangSec, May 2018 24 / 32

slide-35
SLIDE 35

Secure Code by Post-Hoc Verification

For a given encode/decode pair on a given spec:

Formally verify encoder/decoder code

However

Expertise? Effort?! Every spec or code update requires redoing verification.

What might we verify?

Full verification WRT ASN.1 semantics: highly infeasible Verify encode/decode consistency (round trip property): feasible

have proof of memory safety as a consequence

Mark Tullsen (Galois, Inc.) ASN.1 Challenges and Possibilities LangSec, May 2018 25 / 32

slide-36
SLIDE 36

Secure Code by Post-Hoc Verification

For a given encode/decode pair on a given spec:

Formally verify encoder/decoder code

However

Expertise? Effort?! Every spec or code update requires redoing verification.

What might we verify?

Full verification WRT ASN.1 semantics: highly infeasible Verify encode/decode consistency (round trip property): feasible

have proof of memory safety as a consequence

We’ve done this: A formal verification of 1K+ lines of C

Basic Safety Message in V2V (part one, a subset of ASN.1) Refer to our CAV 2018 paper

Mark Tullsen (Galois, Inc.) ASN.1 Challenges and Possibilities LangSec, May 2018 25 / 32

slide-37
SLIDE 37

Secure Code by Intelligent Consensus Testing

Question: Are implementations A, B, C equivalent? Method

1

Create intelligent test-generation capabilities

legal and illegal values quickcheck/smallcheck like test generation (not just generating every number in INTEGER(1..1000000)

2

Create the glue code to run tests on each implementation

Non-trivial: Every compiler (or library) has a different API for creating values, encoding, and decoding!

3

For each test, verify all implementations match.

Mark Tullsen (Galois, Inc.) ASN.1 Challenges and Possibilities LangSec, May 2018 26 / 32

slide-38
SLIDE 38

1

Introduction

2

Five Things to Like About ASN.1

3

Obstacles to Secure ASN.1

4

Approaches to Secure ASN.1 Encoders/Decoders

5

Galois’ Current & Future Work

Mark Tullsen (Galois, Inc.) ASN.1 Challenges and Possibilities LangSec, May 2018 27 / 32

slide-39
SLIDE 39

Secure Code by Post-Hoc Verification

Done

Accomplished verification of code for V2V Basic Safety Message (J2735.asn) The automatic verification needed a bit of expert assistance

i.e., providing lemmas to allow SAW to terminate

Doesn’t support all ASN.1 constructs

Next Steps

Get the verification "automated"

generate lemmas/hints for SAW when we generate the C code

Support more ASN.1 features

Future Goal

Given any ASN.1 specification, generate valid C code and sufficient lemmas/hints to ensure SAW will terminate.

Mark Tullsen (Galois, Inc.) ASN.1 Challenges and Possibilities LangSec, May 2018 28 / 32

slide-40
SLIDE 40

Secure Code by Intelligent Consensus Testing

(New work the DOT is funding us to do.) Question: Are implementations A, B, C equivalent? Method

1

Create intelligent test-generation capabilities

2

Create the glue code to run tests on each implementation

Research: capture the commonality in a DSL

3

For each test, verify all implementations match.

Status

In progress. Goal: consensus among 2-3, eventually . . . Developing something like ILS so as to get results that apply to multiple encoding schemes.

Mark Tullsen (Galois, Inc.) ASN.1 Challenges and Possibilities LangSec, May 2018 29 / 32

slide-41
SLIDE 41

Questions?

Mark Tullsen (Galois, Inc.) ASN.1 Challenges and Possibilities LangSec, May 2018 30 / 32

slide-42
SLIDE 42

Back Up Slides:

Mark Tullsen (Galois, Inc.) ASN.1 Challenges and Possibilities LangSec, May 2018 31 / 32

slide-43
SLIDE 43

Approach One: Abandon Ship?

Forgo ASN.1: roll your own (or pick some trendy) data serializer/deserializer

E.g., protocol buffers, json, avro(json), xml(..), etc, etc.

Nice

Could reduce the complexity issues Relevant for a new, not-wanting-to-play-with-others format

Mark Tullsen (Galois, Inc.) ASN.1 Challenges and Possibilities LangSec, May 2018 32 / 32

slide-44
SLIDE 44

Approach One: Abandon Ship?

Forgo ASN.1: roll your own (or pick some trendy) data serializer/deserializer

E.g., protocol buffers, json, avro(json), xml(..), etc, etc.

Nice

Could reduce the complexity issues Relevant for a new, not-wanting-to-play-with-others format

But generally these

lack most of our Five Things to Like have no separable "specification" of the data

are not primarily a data description language

are tied to implementation(s)

is there a specification for the encoding?

And

we still have the verification effort,

Mark Tullsen (Galois, Inc.) ASN.1 Challenges and Possibilities LangSec, May 2018 32 / 32

slide-45
SLIDE 45

Approach One: Abandon Ship?

Forgo ASN.1: roll your own (or pick some trendy) data serializer/deserializer

E.g., protocol buffers, json, avro(json), xml(..), etc, etc.

Nice

Could reduce the complexity issues Relevant for a new, not-wanting-to-play-with-others format

But generally these

lack most of our Five Things to Like have no separable "specification" of the data

are not primarily a data description language

are tied to implementation(s)

is there a specification for the encoding?

And

we still have the verification effort, can we just stop re-inventing the wheel!

we could be using and contributing to the library of ASN.1 defined formats

Mark Tullsen (Galois, Inc.) ASN.1 Challenges and Possibilities LangSec, May 2018 32 / 32