verification of low-level crypto- protocol implementations

43
Verification of Low Verification of Low - - level Crypto level Crypto - - Protocol Implementations Using Protocol Implementations Using Automated Theorem Proving Automated Theorem Proving Jan Jan J J ü ü rjens rjens (contrib. Mark (contrib. Mark Yampolskiy Yampolskiy ) ) Software & Systems Engineering Software & Systems Engineering TU M TU M u u nich nich http://www4.in.tum.de/~ http://www4.in.tum.de/~ juerjens juerjens

Upload: others

Post on 20-Feb-2022

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Verification of Low-level Crypto- Protocol Implementations

Verification of LowVerification of Low--level Cryptolevel Crypto--Protocol Implementations Using Protocol Implementations Using

Automated Theorem ProvingAutomated Theorem ProvingJan Jan JJüürjensrjens

(contrib. Mark (contrib. Mark YampolskiyYampolskiy))

Software & Systems EngineeringSoftware & Systems EngineeringTU MTU Muunichnich

http://www4.in.tum.de/~http://www4.in.tum.de/~juerjensjuerjens

Page 2: Verification of Low-level Crypto- Protocol Implementations

Jan Jürjens, TU Munich: Verification of Crypto-Protocol Implementations 2

Software Engineering & Security

„Penetrate-and-patch“ (aka „banana strategy):

• insecure

• disruptiveTraditional formal methods: limited

adoptation in industry.• training people• constructing formal specifications.

Page 3: Verification of Low-level Crypto- Protocol Implementations

Jan Jürjens, TU Munich: Verification of Crypto-Protocol Implementations 3

Model-based Security

Increase security with boundedinvestment in time, costs:

• Extract models from artefacts arising in industrial development and use of security-critical systems (UML models, source code, configuration data).

• Tool-supported, theoretically sound,efficient automated security analysis.

Page 4: Verification of Low-level Crypto- Protocol Implementations

Jan Jürjens, TU Munich: Verification of Crypto-Protocol Implementations 4

Model-based Security Engineering

• Analyze (UMLsec) models against securityrequirements.

• Generate code (or tests) from models.

• Generate models fromevolving or legacy code.

Goal: model-based = source-code based.

Requirements

Models

Requirements

Models

CodeCode

Analyze

Codegen.Testgen.

Modelgen./Reverse E.

Page 5: Verification of Low-level Crypto- Protocol Implementations

Jan Jürjens, TU Munich: Verification of Crypto-Protocol Implementations 5

Security Analysis of C-Programs

Goal: Logic-based security verification of C programs which is as

• automatic and• completeas possible. Note: can‘t be both perfectly automated and

complete: Security in general undecidable.Here: emphasize automation.

Page 6: Verification of Low-level Crypto- Protocol Implementations

Jan Jürjens, TU Munich: Verification of Crypto-Protocol Implementations 6

Crypto-Hardware API‘s (PKCS 11)

Here: support correct use of PKCS 11 API‘s.Keep track of session handles.C_GetAttributeValue obtains attribute valueC_SetAttributeValue modifies attribute valueC_Encrypt encrypts single-part data C_Decrypt decrypts encrypted dataC_Digest digests single-part dataC_Sign signs single-part data C_VerifyRecover verifies signature, data recoveredC_GenerateKey generates a secret keyC_GenerateKeyPair generates a key pairC_GenerateRandom generates random data

Page 7: Verification of Low-level Crypto- Protocol Implementations

Jan Jürjens, TU Munich: Verification of Crypto-Protocol Implementations 7

Security Analysis

Following Dolev, Yao (1982): To analyze system, verify against attacker model from threat scenarios in deployment diagrams who

• may participate in some protocol runs,• knows some data in advance,• may intercept messages on some links,• injects messages that it can produce in some

links• may access certain nodes.

Page 8: Verification of Low-level Crypto- Protocol Implementations

Jan Jürjens, TU Munich: Verification of Crypto-Protocol Implementations 8

Adversary: Simulation

A BAdversary

m(x)

Adversaryknowledge:

k-1, y,

m(x)

x

return({z}k)

[argb,1,1 = x]

{z}k, z

return({y::x}z)

Page 9: Verification of Low-level Crypto- Protocol Implementations

Jan Jürjens, TU Munich: Verification of Crypto-Protocol Implementations 9

Generate control flowgraph (e.g. with aicall(Absint, Germany)).

Transform to Mealy Machines:trans (state,inpattern,condition,action,nextstate)where action can be outpattern or

localvar:=value.Translate to abstract interpretation in FOL

formula.

Control Flow Graph

Page 10: Verification of Low-level Crypto- Protocol Implementations

Jan Jürjens, TU Munich: Verification of Crypto-Protocol Implementations 10

Security Analysis in First-order Logic

Approximate set of possible data valuesflowing through system from above.

Predicate knows(E) meaning that the adversary may get to know E during the execution of the protocol.

E.g. secrecy: For any secret s, check whether can derive knows(s) using automated theorem prover.

Page 11: Verification of Low-level Crypto- Protocol Implementations

Jan Jürjens, TU Munich: Verification of Crypto-Protocol Implementations 11

Cryptographic Expressions IExp: quotient of term algebra generated from

sets Data, Keys, Var of symbols using• _::_ (concatenation), head(_), tail(_),• (_)-1 (inverse keys)• { _ }_ (encryption)• Dec_( ) (decryption)• Sign_( ) (signing)• Ext_( ) (extracting from signature)

(each w. session parameter) and equations:

Page 12: Verification of Low-level Crypto- Protocol Implementations

Jan Jürjens, TU Munich: Verification of Crypto-Protocol Implementations 12

Cryptographic Expressions II

• ∀E,K,S,S’,S’’.DecK;S’’-1({E;S}K;S’)=E

• ∀E,K,S,S’,S’’.ExtK(SignK;S‘‘-1(E;S);S‘)=E

• ∀E1,E2,,S,S’.head(E1::SE2;S’)=E1

• ∀E1,E2,S,S’.tail(E1::SE2;S’)=E2

Write E1::E2::E3 for E1::(E2::E3) and fst(E1::E2) for head(E1::E2) etc.

Can include further crypto-specific primitives and laws (XOR, …).

Page 13: Verification of Low-level Crypto- Protocol Implementations

Jan Jürjens, TU Munich: Verification of Crypto-Protocol Implementations 13

First-order Logic: Basic Rules

Define knows(E) for any E initially known to the adversary.

For evolving knowledge define∀ E1,E2,S.(knows(E1)∧ knows(E2) �

knows(E1::SE2) ∧ knows({E1;S}E2) ∧knows(DecE2(E1;S)) ∧ knows(SignE2 (E1;S)) ∧knows(ExtE2 (E1;S)))

∀ E,S.(knows(E) �knows(head(E;S)) ∧ knows(tail(E;S)))

Page 14: Verification of Low-level Crypto- Protocol Implementations

Jan Jürjens, TU Munich: Verification of Crypto-Protocol Implementations 14

… Translate to 1st Order Logic

Graph transitionTR1=(in(msg_in),cond(msg_in),out(msg_out))followed by TR2 gives predicate PRED(TR1)=

� msg_in. [knows(msg_in) � cond(msg_in)� � knows(msg_out)� PRED(TR2)]

Abstraction (e.g. from senders, receivers): findall attacks, may have false positives.

Check whether can derive threat conjecture(e.g. knows(s) for a secret s) from axioms.

Page 15: Verification of Low-level Crypto- Protocol Implementations

Jan Jürjens, TU Munich: Verification of Crypto-Protocol Implementations 15

Example: Proposed Variant of TLS (SSL)

Presented at IEEE Infocom 1999.

Goal: send secret protected by session key using fewer server resources.

Page 16: Verification of Low-level Crypto- Protocol Implementations

Jan Jürjens, TU Munich: Verification of Crypto-Protocol Implementations 16

Example: Translation to Logic

knows(N)� knows(KC)� knows(SignKC-1(C::KC))� � init1,init2,init3.[knows(init1)� knows(init2)�

knows(init3) � snd(Extinit2(init3)) = init2� knows({SignKS-1(…)}…)� […] � […� ...]…]

Page 17: Verification of Low-level Crypto- Protocol Implementations

Jan Jürjens, TU Munich: Verification of Crypto-Protocol Implementations 17

Preprocessing of code

For simplification and efficiency apply semantics-preserving transformations to the C program:

• use of single-assignment variables• eliminate side effects• factor out pointer arithmeticAnalyze loops up to a fixed number of iterations.

No so much of a restriction when analyzingsecure interactions in crypto protocols.

Include annotations to abstract cryptofunctions etc.

Page 18: Verification of Low-level Crypto- Protocol Implementations

Jan Jürjens, TU Munich: Verification of Crypto-Protocol Implementations 18

Client I

Page 19: Verification of Low-level Crypto- Protocol Implementations

Jan Jürjens, TU Munich: Verification of Crypto-Protocol Implementations 19

Client II

Page 20: Verification of Low-level Crypto- Protocol Implementations

Jan Jürjens, TU Munich: Verification of Crypto-Protocol Implementations 20

Surprise …

� Completely insecure wrt stated goals.

But why ? Use prolog-based attack generator.

Can derive knows(s). That is: Protocol does not preserve secrecy of s against adversaries.

Page 21: Verification of Low-level Crypto- Protocol Implementations

Jan Jürjens, TU Munich: Verification of Crypto-Protocol Implementations 21

Man-in-the-Middle Attack

Page 22: Verification of Low-level Crypto- Protocol Implementations

Jan Jürjens, TU Munich: Verification of Crypto-Protocol Implementations 22

Biometric Authentication System

In development by large German company.

In joint project, use presented securityanalysis tools at given UML specification.

So far, have discovered three major attacksagainst subsequently improved versions(misuse counter circumvented by dropping / replaying messages, smart-card insufficientlyauthenticated by recombing sessions).

Page 23: Verification of Low-level Crypto- Protocol Implementations

Jan Jürjens, TU Munich: Verification of Crypto-Protocol Implementations 23

Conclusions

Code security verification using assertions:• formally based approach• automated tool support• industrially used programming language• integrated approach (specifications, source-

code, configuration data)Future:• Virtual C execution machine in tptp instead of

manual code tptp annotations…

Page 24: Verification of Low-level Crypto- Protocol Implementations

Jan Jürjens, TU Munich: Verification of Crypto-Protocol Implementations 24

Resources

TUM TB Dez. ‘04 (with T. Kuhn)International Conference for

Software Maintenance 2005Models / UML 2005 (with S. Houmb)

More information (papers, slides, tool, …): http://www4.in.tum.de/~juerjens

Page 25: Verification of Low-level Crypto- Protocol Implementations

Jan Jürjens, TU Munich: Verification of Crypto-Protocol Implementations 25

Page 26: Verification of Low-level Crypto- Protocol Implementations

Jan Jürjens, TU Munich: Verification of Crypto-Protocol Implementations 26

Abstraction

Enable efficient automated analysis byabstraction (e.g. functions or code-blocks):

• symbolic representation of cryptographic orarithmetic routines

• technical infrastructure (packet_send, buffer_copy, …)

• data structures (e.g. a->b)Factor out pointers usage.

Page 27: Verification of Low-level Crypto- Protocol Implementations

Jan Jürjens, TU Munich: Verification of Crypto-Protocol Implementations 27

Sequence Diagram Specification

Page 28: Verification of Low-level Crypto- Protocol Implementations

Jan Jürjens, TU Munich: Verification of Crypto-Protocol Implementations 28

Code Annotations#ifndef _TLS_C2TPTP_H#define _TLS_C2TPTP_H

//@C2TPTP_START// SEND (send, 3)// RECEIVE (rcv, 2)// CONST const_c_cert_ca := sign(conc(c, k_c), inv(k_ca))// CONST const_s_cert_ca := sign(conc(s, k_s), inv(k_ca))//@C2TPTP_END

#endif // _TLS_C2TPTP_H

Page 29: Verification of Low-level Crypto- Protocol Implementations

Jan Jürjens, TU Munich: Verification of Crypto-Protocol Implementations 29

TLS Overview

Page 30: Verification of Low-level Crypto- Protocol Implementations

Jan Jürjens, TU Munich: Verification of Crypto-Protocol Implementations 30

Client I

Page 31: Verification of Low-level Crypto- Protocol Implementations

Jan Jürjens, TU Munich: Verification of Crypto-Protocol Implementations 31

Client IIconst_c_cert_ca

Page 32: Verification of Low-level Crypto- Protocol Implementations

Jan Jürjens, TU Munich: Verification of Crypto-Protocol Implementations 32

Server I

Page 33: Verification of Low-level Crypto- Protocol Implementations

Jan Jürjens, TU Munich: Verification of Crypto-Protocol Implementations 33

Server II

const_s_cert_ca

Page 34: Verification of Low-level Crypto- Protocol Implementations

Jan Jürjens, TU Munich: Verification of Crypto-Protocol Implementations 34

The Fix

e-Setheo: knows(s) not derivable. Thus „secure“ in above sense.

Page 35: Verification of Low-level Crypto- Protocol Implementations

Jan Jürjens, TU Munich: Verification of Crypto-Protocol Implementations 35

Interpretation

Why examine knows(s) rather than secret(s) ?�Really only care about initial models of the

axioms (basic axioms, protocol axioms and initial adversary knowledge) - our „idealizedimplementation“. Models basic assumptionson the security of the cryptographicalgorithms (viewed at our level of abstraction): Cryptographic data does notfulfill any unintended equations (or theadversary cannot learn these).

Page 36: Verification of Low-level Crypto- Protocol Implementations

Jan Jürjens, TU Munich: Verification of Crypto-Protocol Implementations 36

Modular Verification: Idea

For given protocol try to establish assertions

a1 � g1 .Include into C code as annotations.Check whether axioms together with

annotations entail threat conjecture.

Page 37: Verification of Low-level Crypto- Protocol Implementations

Jan Jürjens, TU Munich: Verification of Crypto-Protocol Implementations 37

Modular Verification: Example

If for protocol p1, basic axioms, protocol axiomsand initial adversary knowledge entails knows(s) (have counter-example) then in the initial modelsatisfying these axioms (our „idealizedimplementation“) the adversary can learn s.

We generate the assertioninit_knowledge_axioms � knows(s)

(Careful: cannot just generate … � not(knows(s)) otherwise without possible inconsistency.)

Page 38: Verification of Low-level Crypto- Protocol Implementations

Jan Jürjens, TU Munich: Verification of Crypto-Protocol Implementations 38

Mutual authentication withchallenge & response

Generate shared key

Forged smart-card after authentic.; replay old session key

Modular Verification: Application

Page 39: Verification of Low-level Crypto- Protocol Implementations

Jan Jürjens, TU Munich: Verification of Crypto-Protocol Implementations 39

Control Flow graph to State Machine

Page 40: Verification of Low-level Crypto- Protocol Implementations

Jan Jürjens, TU Munich: Verification of Crypto-Protocol Implementations 40

CFG to State Machine I

Page 41: Verification of Low-level Crypto- Protocol Implementations

Jan Jürjens, TU Munich: Verification of Crypto-Protocol Implementations 41

CFG to State Machine II

Page 42: Verification of Low-level Crypto- Protocol Implementations

Jan Jürjens, TU Munich: Verification of Crypto-Protocol Implementations 42

TLS Variant in TPTP notation I

Page 43: Verification of Low-level Crypto- Protocol Implementations

Jan Jürjens, TU Munich: Verification of Crypto-Protocol Implementations 43

TLS Variant in TPTP notation II