114
© 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved. © 2015, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Byron Cook [email protected] November 29, 2016 SEC401 Automated Formal Reasoning About AWS Systems securing Customers with Mathematical Logic

AWS re:Invent 2016: Automated Formal Reasoning About AWS Systems (SEC401)

Embed Size (px)

Citation preview

Page 1: AWS re:Invent 2016: Automated Formal Reasoning About AWS Systems (SEC401)

© 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved.© 2015, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

Byron Cook

[email protected]

November 29, 2016

SEC401

Automated Formal Reasoning About AWS Systemssecuring Customers with Mathematical Logic

Page 2: AWS re:Invent 2016: Automated Formal Reasoning About AWS Systems (SEC401)

Shared security model

• Securing the cloud

• “How do we know that the AWS crypto primitives are correctly

implemented and not vulnerable to side-channel attacks?”

• “How do we know that Amazon EC2’s virtualization layer protects

against memory corruption-based attacks?”

• Secure usage

• “Could my AWS IAM policy allow unintended users access to my S3

bucket?”

• “Am I only allowing one instance in my VPC to send outgoing

network packets?”

Page 3: AWS re:Invent 2016: Automated Formal Reasoning About AWS Systems (SEC401)

Shared security model

• Helping customers be secure in the cloud

• “Could my IAM policy allow unintended users access to my Amazon

S3 bucket?”

• “Am I allowing only one instance in my VPC to send outgoing

network packets?”

• Securing the cloud

• “How do we know that the AWS crypto primitives are correctly

implemented?”

• “How do we know that Amazon EC2’s virtualization layer protects

against memory corruption-based attacks?”

Page 4: AWS re:Invent 2016: Automated Formal Reasoning About AWS Systems (SEC401)

Shared security model

• Helping customers be secure in the cloud

• “Could my IAM policy allow unintended users access to my Amazon

S3 bucket?”

• “Am I allowing only one instance in my VPC to send outgoing

network packets?”

• Securing the cloud

• “How do we know that the AWS crypto primitives are correctly

implemented?”

• “How do we know that Amazon EC2’s virtualization layer protects

against memory corruption-based attacks?”

Page 5: AWS re:Invent 2016: Automated Formal Reasoning About AWS Systems (SEC401)

Shared security model

• Helping customers be secure in the cloud

• “Could my IAM policy allow unintended users access to my Amazon

S3 bucket?”

• “Am I allowing only one instance in my VPC to send outgoing

network packets?”

• Securing the cloud

• “How do we know that the AWS crypto primitives are correctly

implemented?”

• “How do we know that Amazon EC2’s virtualization layer protects

against memory corruption-based attacks?”

Page 6: AWS re:Invent 2016: Automated Formal Reasoning About AWS Systems (SEC401)

Shared security model

• Helping customers be secure in the cloud

• “Could my IAM policy allow unintended users access to my Amazon

S3 bucket?”

• “Am I allowing only one instance in my VPC to send outgoing

network packets?”

• Securing the cloud

• “How do we know that the AWS crypto primitives are correctly

implemented?”

• “How do we know that the Amazon EC2 virtualization layer protects

against memory corruption-based attacks?”

Page 7: AWS re:Invent 2016: Automated Formal Reasoning About AWS Systems (SEC401)

Shared security model

• Helping customers be secure in the cloud

• “Could my AWS IAM policy allow unintended users access to my S3

bucket?”

• “Am I allowing only one instance in my VPC to send outgoing

network packets?”

• Securing the cloud

• “How do we know that the AWS crypto primitives are correctly

implemented?”

• “How do we know that the Amazon EC2 virtualization layer protects

against memory corruption-based attacks?”

Page 8: AWS re:Invent 2016: Automated Formal Reasoning About AWS Systems (SEC401)

Shared security model

• Helping customers be secure in the cloud

• “Could my AWS IAM policy allow unintended users access to my S3

bucket?”

• “Am I allowing only one instance in my VPC to send outgoing

network packets?”

• Securing the cloud

• “How do we know that the AWS crypto primitives are correctly

implemented?”

• “How do we know that the Amazon EC2 virtualization layer protects

against memory corruption-based attacks?”

Page 9: AWS re:Invent 2016: Automated Formal Reasoning About AWS Systems (SEC401)

AWS security: Raising the bar on security

• Secure usage of AWS components

• Amazon Inspector, Amazon CloudWatch, AWS Config Rules, etc

• Tools that apply mechanized reasoning in mathematical logic to

provide additional assurance

• Securing the cloud

• Extensive penetration testing, continuous monitoring, etc

• Mechanized reasoning in mathematical logic to provide additional

assurance

Page 10: AWS re:Invent 2016: Automated Formal Reasoning About AWS Systems (SEC401)

AWS security: Raising the bar on security

• Helping customers be secure in the cloud

• Amazon Inspector, AWS Config Rules, etc

• Tools that apply mechanized reasoning in mathematical logic to

provide additional assurance

• Securing the cloud

• Extensive penetration testing, continuous monitoring, etc

• Mechanized reasoning in mathematical logic to provide additional

assurance

Page 11: AWS re:Invent 2016: Automated Formal Reasoning About AWS Systems (SEC401)

AWS security: Raising the bar on security

• Helping customers be secure in the cloud

• Amazon Inspector, AWS Config Rules, etc

• Mechanized reasoning in mathematical logic to provide additional

assurance

• Securing the cloud

• Extensive penetration testing, continuous monitoring, etc

• Mechanized reasoning in mathematical logic to provide additional

assurance

Page 12: AWS re:Invent 2016: Automated Formal Reasoning About AWS Systems (SEC401)

AWS security: Raising the bar on security

• Helping customers be secure in the cloud

• Amazon Inspector, AWS Config Rules, etc

• Mechanized reasoning in mathematical logic to provide additional

assurance

• Securing the cloud

• Penetration testing, continuous monitoring, compliance certification,

etc

• Mechanized reasoning in mathematical logic to provide additional

assurance

Page 13: AWS re:Invent 2016: Automated Formal Reasoning About AWS Systems (SEC401)

AWS security: Raising the bar on security

• Helping customers be secure in the cloud

• Amazon Inspector, AWS Config Rules, etc

• Mechanized reasoning in mathematical logic to provide additional

assurance

• Securing the cloud

• Penetration testing, continuous monitoring, compliance certification,

etc

• Mechanized reasoning in mathematical logic to provide additional

assurance

Page 14: AWS re:Invent 2016: Automated Formal Reasoning About AWS Systems (SEC401)

Questions answered in this talk

• What is “Mechanized reasoning in mathematical logic” ?

• What are some examples of what AWS doing in this space?

Page 15: AWS re:Invent 2016: Automated Formal Reasoning About AWS Systems (SEC401)

Mechanized reasoning in mathematical logic

• Proofs: 360 BC — 1970s AD

• Examples:

• Euclid’s Infinitude of Primes

• Godel’s incompleteness theorem

• Turing’s Halting problem undecidability

• Four-color theorem

• Odd-order theorem

• …..

• …..

• …..

Page 16: AWS re:Invent 2016: Automated Formal Reasoning About AWS Systems (SEC401)

Mechanized reasoning in mathematical logic

• Proofs: 360 BC — 1970s AD

• Examples:

• Euclid’s Infinitude of Primes

• Gödel’s incompleteness theorem

• Turing’s Halting problem undecidability

• Odd-order theorem

• …..

• …..

• …..

Page 17: AWS re:Invent 2016: Automated Formal Reasoning About AWS Systems (SEC401)

Mechanized reasoning in mathematical logic

• Proofs: 360 BC — 1970s AD

• Examples:

• Euclid’s Infinitude of Primes

• Gödel’s incompleteness theorem

• Turing’s Halting problem undecidability

• Odd-order theorem

• …..

• …..

• …..

Arguments found and

checked by humans

Page 18: AWS re:Invent 2016: Automated Formal Reasoning About AWS Systems (SEC401)

Mechanized reasoning in mathematical logic

• Proofs: 360 BC — 1970s AD

• Examples:

• Euclid’s Infinitude of Primes

• Gödel’s incompleteness theorem

• Turing’s Halting problem undecidability

• Odd-order theorem

• …..

• …..

• …..

• Harder: finding

the argument

• Easier: checking

the argument

Page 19: AWS re:Invent 2016: Automated Formal Reasoning About AWS Systems (SEC401)

Mechanized reasoning in mathematical logic

• Proofs: 1970s AD — Current

• New: human found and mechanically checked

• Examples:

• Euclid’s Infinitude of Primes

• Gödel’s Incompleteness theorem

• Turing’s Halting problem undecidability

• Odd-order theorem

• Four-color theorem

• …..

• …..

• …..

Page 20: AWS re:Invent 2016: Automated Formal Reasoning About AWS Systems (SEC401)

Mechanized reasoning in mathematical logic

• Proofs: 1970s AD — Current

• New: human found and mechanically checked

• Examples:

• …..

• Boeing "Little Bird" helicopter (seL4 OS-based mission computer)

• Royal Navy Ship/Helicopter Operating Limits Unit

• Lockheed Martin C130J Mission Computers

• Rolls Royce Trent Series Health Monitoring Units

• AMD K5 floating point square root microcode

• Intel CPU arithmetic and logical operations

• …..

Page 21: AWS re:Invent 2016: Automated Formal Reasoning About AWS Systems (SEC401)

Mechanized reasoning in mathematical logic

• Proofs: 2001 AD — Current

• Increasingly mechanically found and mechanically checked

• Examples:

• ……

• ……

• Airbus 360 primary flight control software

• Paris Metro (RATP)

• Bombardier ILLBV950L2 railway interlocking system

• Mars Rover data management subsystem

• ……

• ……

Page 22: AWS re:Invent 2016: Automated Formal Reasoning About AWS Systems (SEC401)

Core ideas behind the advances/buzzwords

• Making NP-complete problems feel P-time in practice

• Conflict-clause driven learning

• Back-jumping

• Random-restarts

• SAT and SAT modulo theories

• Making undecidable problems feel decidable in practice

• Abstraction to finite/tractible problems

• Counterexample-guided abstraction refinement

• Interpolation for guessing inductive invariants

Page 23: AWS re:Invent 2016: Automated Formal Reasoning About AWS Systems (SEC401)

Core ideas behind the advances/buzzwords

• Making NP-complete problems feel P-time in practice

• Conflict-clause driven learning

• Back-jumping

• Random-restarts

• SAT and SAT modulo theories

• Making undecidable problems feel decidable in practice

• Abstraction to finite/tractible problems

• Counterexample-guided abstraction refinement

• Interpolation for guessing inductive invariants

Page 24: AWS re:Invent 2016: Automated Formal Reasoning About AWS Systems (SEC401)

Core ideas behind the advances/buzzwords

• Making NP-complete problems feel P-time in practice

• Conflict-clause driven learning

• Back-jumping

• Random-restarts

• SAT and SAT modulo theories

• Making undecidable problems feel decidable in practice

• Abstraction to finite/tractible problems

• Counterexample-guided abstraction refinement

• Interpolation for guessing inductive invariants

• P-time = polynomial time = “tractable”

• NP-complete = nondeterministic polynomial time

= “intractable”

Page 25: AWS re:Invent 2016: Automated Formal Reasoning About AWS Systems (SEC401)

Core ideas behind the advances/buzzwords

• Making NP-complete problems feel P-time in practice

• Conflict-clause driven learning

• Back-jumping

• Random-restarts

• SAT and SAT modulo theories

• Making undecidable problems feel decidable in practice

• Abstraction to finite/tractible problems

• Counterexample-guided abstraction refinement

• Interpolation for guessing inductive invariants

Page 26: AWS re:Invent 2016: Automated Formal Reasoning About AWS Systems (SEC401)

Core ideas behind the advances/buzzwords

• Making NP-complete problems feel P-time in practice

• Conflict-clause driven learning

• Back-jumping

• Random-restarts

• SAT and SAT modulo theories

• Making undecidable problems feel decidable in practice

• Abstraction to finite/tractible problems

• Counterexample-guided abstraction refinement

• Interpolation for guessing inductive invariants

Page 27: AWS re:Invent 2016: Automated Formal Reasoning About AWS Systems (SEC401)

Core ideas behind the advances/buzzwords

• Making NP-complete problems feel P-time in practice

• Conflict-clause driven learning

• Back-jumping

• Random-restarts

• SAT and SAT modulo theories

• Making undecidable problems feel decidable in practice

• Abstraction to finite/tractible problems

• Counterexample-guided abstraction refinement

• Interpolation for guessing inductive invariants

Just buzzwords…..

Page 28: AWS re:Invent 2016: Automated Formal Reasoning About AWS Systems (SEC401)

Core ideas behind the advances/buzzwords

• Making NP-complete problems feel P-time in practice

• Conflict-clause driven learning

• Back-jumping

• Random-restarts

• SAT and SAT modulo theories

• Making undecidable problems feel decidable in practice

• Abstraction to finite/tractable problems

• Counterexample-guided abstraction refinement

• Interpolation for guessing inductive invariants

Page 29: AWS re:Invent 2016: Automated Formal Reasoning About AWS Systems (SEC401)

Core ideas behind the advances/buzzwords

• Making NP-complete problems feel P-time in practice

• Conflict-clause driven learning

• Back-jumping

• Random-restarts

• SAT and SAT modulo theories

• Making undecidable problems feel decidable in practice

• Abstraction to finite/tractable problems

• Counterexample-guided abstraction refinement

• Interpolation for guessing inductive invariants

Page 30: AWS re:Invent 2016: Automated Formal Reasoning About AWS Systems (SEC401)

Core ideas behind the advances/buzzwords

• Making NP-complete problems feel P-time in practice

• Conflict-clause driven learning

• Back-jumping

• Random-restarts

• SAT and SAT modulo theories

• Making undecidable problems feel decidable in practice

• Abstraction to finite/tractable problems

• Counterexample-guided abstraction refinement

• Interpolation for guessing inductive invariants

Just buzzwords…..

Page 31: AWS re:Invent 2016: Automated Formal Reasoning About AWS Systems (SEC401)

Core ideas behind the advances/buzzwords

• Making NP-complete problems feel P-time in practice

• Conflict-clause driven learning

• Back-jumping

• Random-restarts

• SAT and SAT modulo theories

• Making undecidable problems feel decidable in practice

• Abstraction to finite/tractable problems

• Counterexample-guided abstraction refinement

• Interpolation for guessing inductive invariants

Example open source

tools: Yices, MiniSAT

Page 32: AWS re:Invent 2016: Automated Formal Reasoning About AWS Systems (SEC401)

Core ideas behind the advances/buzzwords

• Making NP-complete problems feel P-time in practice

• Conflict-clause driven learning

• Back-jumping

• Random-restarts

• SAT and SAT modulo theories

• Making undecidable problems feel decidable in practice

• Abstraction to finite/tractable problems

• Counterexample-guided abstraction refinement

• Interpolation for guessing inductive invariants

Example open source

tools: Yices, MiniSAT

Example open source

tools: Coq, Jhorn

Page 33: AWS re:Invent 2016: Automated Formal Reasoning About AWS Systems (SEC401)

Core ideas behind the advances/buzzwords

• Making NP-complete problems feel P-time in practice

• Conflict-clause driven learning

• Back-jumping

• Random-restarts

• SAT and SAT modulo theories

• Making undecidable problems feel decidable in practice

• Abstraction to finite/tractable problems

• Counterexample-guided abstraction refinement

• Interpolation for guessing inductive invariants

Page 34: AWS re:Invent 2016: Automated Formal Reasoning About AWS Systems (SEC401)

Example: NP-complete in P-time

• What values of u,w,x,y,z would lead to error()?

if (w<x && x<y && y<z && (x>=z || u<3) && u>10)

error();

• u=4, w=3, x=1, y=10, z=5 ?

if (w<x && x<y && y<z && (w<u || u<3) && x>=z)

error();

Page 35: AWS re:Invent 2016: Automated Formal Reasoning About AWS Systems (SEC401)

Example: NP-complete in P-time

• What values of u,w,x,y,z would lead to error()?

if (w<x && x<y && y<z && (x>=z || u<3) && u>10)

error();

• u=4, w=3, x=1, y=10, z=5 ?

if (w<x && x<y && y<z && (w<u || u<3) && x>=z)

error();

Page 36: AWS re:Invent 2016: Automated Formal Reasoning About AWS Systems (SEC401)

Example: NP-complete in P-time

• What values of u,w,x,y,z would lead to error()?

if (w<x && x<y && y<z && (x>=z || u<3) && u>10)

error();

• u=4, w=3, x=1, y=10, z=5 ?

No because w>=x :

if (w<x && x<y && y<z && (x>=z || u<3) && u>10)

error();

Page 37: AWS re:Invent 2016: Automated Formal Reasoning About AWS Systems (SEC401)

Example: NP-complete in P-time

• What values of u,w,x,y,z would lead to error()?

if (w<x && x<y && y<z && (x>=z || u<3) && u>10)

error();

• u=4, w=3, x=18, y=10, z=5 ?

No because x>=y :

Page 38: AWS re:Invent 2016: Automated Formal Reasoning About AWS Systems (SEC401)

Example: NP-complete in P-time

• What values of u,w,x,y,z would lead to error()?

if (w<x && x<y && y<z && (x>=z || u<3) && u>10)

error();

• u=4, w=3, x=18, y=10, z=5 ?

No because x>=y :

if (w<x && x<y && y<z && (w<u || u<3) && x>=z)

error();

Page 39: AWS re:Invent 2016: Automated Formal Reasoning About AWS Systems (SEC401)

Example: NP-complete in P-time

• What values of u,w,x,y,z would lead to error()?

if (w<x && x<y && y<z && (x>=z || u<3) && u>10)

error();

• u=?, w=?, x=?, y=?, z=?

• SAT: If the variables range over 32-bit integers there are 2^(32*5)

possible combinations.

• SMT: If the variables range over reals/rationals/integers there are an

infinite number of combinations (though still decidable)

Page 40: AWS re:Invent 2016: Automated Formal Reasoning About AWS Systems (SEC401)

Example: NP-complete in P-time

w<z && x<y && y<z && (x>=z || u<3) && u>10

Page 41: AWS re:Invent 2016: Automated Formal Reasoning About AWS Systems (SEC401)

Example: NP-complete in P-time

w<z && x<y && y<z && (x>=z || u<3) && u>10

Page 42: AWS re:Invent 2016: Automated Formal Reasoning About AWS Systems (SEC401)

Example: NP-complete in P-time

w<z && x<y && y<z && u<3 && u>10

w<z && x<y && y<z && x>=z && u>10

w<z && x<y && y<z && (x>=z || u<3) && u>10

Page 43: AWS re:Invent 2016: Automated Formal Reasoning About AWS Systems (SEC401)

Example: NP-complete in P-time

w<z && x<y && y<z && u<3 && u>10

w<z && x<y && y<z && x>=z && u>10

w<z && x<y && y<z && u<3 && u>10

w<z && x<y && y<z && x>=z && u>10

w<z && x<y && y<z && (x>=z || u<3) && u>10

Page 44: AWS re:Invent 2016: Automated Formal Reasoning About AWS Systems (SEC401)

Example: NP-complete in P-time

w<z && x<y && y<z && u<3 && u>10

w<z && x<y && y<z && x>=z && u>10

w<z && x<y && y<z && u<3 && u>10

w<z && x<y && y<z && x>=z && u>10

w<z && x<y && y<z && (x>=z || u<3) && u>10

Page 45: AWS re:Invent 2016: Automated Formal Reasoning About AWS Systems (SEC401)

Example: NP-complete in P-time

w<z && x<y && y<z && (x>=z || u<3) && u>10

Page 46: AWS re:Invent 2016: Automated Formal Reasoning About AWS Systems (SEC401)

Example: NP-complete in P-time

w<z && x<y && y<z && (x>=z || u<3) && u>10

Page 47: AWS re:Invent 2016: Automated Formal Reasoning About AWS Systems (SEC401)

Example: NP-complete in P-time

w<z && x<y && y<z && (x>=z || u<3) && u>10

x<y && y<z && x>=z

Page 48: AWS re:Invent 2016: Automated Formal Reasoning About AWS Systems (SEC401)

Example: NP-complete in P-time

w<z && x<y && y<z && (x>=z || u<3) && u>10

&& !(x<y && y<z && x>=z)

x<y && y<z && x>=z

Page 49: AWS re:Invent 2016: Automated Formal Reasoning About AWS Systems (SEC401)

Example: NP-complete in P-time

w<z && x<y && y<z && (x>=z || u<3) && u>10

&& !(x<y && y<z && x>=z)

Page 50: AWS re:Invent 2016: Automated Formal Reasoning About AWS Systems (SEC401)

Core ideas behind the advances/buzzwords

• Making NP-complete problems feel P-time in practice

• Conflict-clause driven learning

• Back-jumping

• Random-restarts

• SAT and SAT modulo theories

• Making undecidable problems feel decidable in practice

• Abstraction to finite/tractable problems

• Counterexample-guided abstraction refinement

• Interpolation for guessing inductive invariants

Page 51: AWS re:Invent 2016: Automated Formal Reasoning About AWS Systems (SEC401)

Core ideas behind the advances/buzzwords

• Making NP-complete problems feel P-time in practice

• Conflict-clause driven learning

• Back-jumping

• Random-restarts

• SAT and SAT modulo theories

• Making undecidable problems feel decidable in practice

• Abstraction to finite/tractable problems

• Counterexample-guided abstraction refinement

• Interpolation for guessing inductive invariants

Page 52: AWS re:Invent 2016: Automated Formal Reasoning About AWS Systems (SEC401)

Example: Induction

if (x>=0 && y>=0) {

r=0;

i=y;

while(i>0) {

i--;

r=r+x;

}

assert(r==x*y);

}

Page 53: AWS re:Invent 2016: Automated Formal Reasoning About AWS Systems (SEC401)

Example: Induction

if (x>=0 && y>=0) {

r=0;

i=y;

while(i>0) {

i--;

r=r+x;

}

assert(r==x*y);

}

Making undecidable

problems feel decidable

in practice

Page 54: AWS re:Invent 2016: Automated Formal Reasoning About AWS Systems (SEC401)

Example: Induction

if (x>=0 && y>=0) {

r=0;

i=y;

while(i>0) {

i--;

r=r+x;

}

assert(r==x*y);

}

Could this

assert

ever fail?

Page 55: AWS re:Invent 2016: Automated Formal Reasoning About AWS Systems (SEC401)

Example: Induction

if (x>=0 && y>=0) {

r=0;

i=y;

while(i>0) {

pre condition: r==(y-i)*x && i>=0

i--;

r=r+x;

post condition: r==(y-i)*x && i>=0

}

assert(r==x*y);

}

Inductive invariant

Inductive invariant

Page 56: AWS re:Invent 2016: Automated Formal Reasoning About AWS Systems (SEC401)

Example: Induction

if (x>=0 && y>=0) {

r=0;

i=y;

while(i>0) {

pre condition: r==(y-i)*x && i>=0

i--;

r=r+x;

post condition: r==(y-i)*x && i>=0

}

assert(r==x*y);

}

Page 57: AWS re:Invent 2016: Automated Formal Reasoning About AWS Systems (SEC401)

Example: Induction

if (x>=0 && y>=0) {

r=0;

i=y;

while(i>0) {

pre condition: r==(y-i)*x && i>=0

i--;

r=r+x;

post condition: r==(y-i)*x && i>=0

}

assert(r==x*y);

}

Page 58: AWS re:Invent 2016: Automated Formal Reasoning About AWS Systems (SEC401)

Example: Induction

if (x>=0 && y>=0) {

r=0;

i=y;

while(i>0) {

pre condition: r==(y-i)*x && i>=0

i--;

r=r+x;

post condition: r==(y-i)*x && i>=0

}

assert(r==x*y);

}

x,y,r,i

A

Page 59: AWS re:Invent 2016: Automated Formal Reasoning About AWS Systems (SEC401)

Example: Induction

if (x>=0 && y>=0) {

r=0;

i=y;

while(i>0) {

pre condition: r==(y-i)*x && i>=0

i--;

r=r+x;

post condition: r==(y-i)*x && i>=0

}

assert(r==x*y);

}

Page 60: AWS re:Invent 2016: Automated Formal Reasoning About AWS Systems (SEC401)

Example: Induction

if (x>=0 && y>=0) {

r=0;

i=y;

while(i>0) {

pre condition: r==(y-i)*x && i>=0

i--;

r=r+x;

post condition: r==(y-i)*x && i>=0

}

assert(r==x*y);

}

Page 61: AWS re:Invent 2016: Automated Formal Reasoning About AWS Systems (SEC401)

Example: Induction

if (x>=0 && y>=0) {

r=0;

i=y;

while(i>0) {

i>0 condition: r==(y-i)*x && i>=0

i--;

r=r+x;

post condition: r==(y-i)*x && i>=0

}

assert(r==x*y);

}

Page 62: AWS re:Invent 2016: Automated Formal Reasoning About AWS Systems (SEC401)

Example: Induction

if (x>=0 && y>=0) {

r=0;

i=y;

while(i>0) {

i>0 condition: r==(y-i)*x && i>=0

i--;

r=r+x;

post condition: r==(y-i)*x && i>=0

}

assert(r==x*y);

}

x,y,r,i

A

Now we ignore how

we got into the loop

Page 63: AWS re:Invent 2016: Automated Formal Reasoning About AWS Systems (SEC401)

Example: Induction

if (x>=0 && y>=0) {

r=0;

i=y;

while(i>0) {

i>0 condition: r==(y-i)*x && i>=0

i’=i-1

r’=r+x

post condition: r’==(y-i’)*x && i’>=0

}

assert(r==x*y);

}

x,y,r,i,r’,i’

A

Now we ignore how

we got into the loop

Page 64: AWS re:Invent 2016: Automated Formal Reasoning About AWS Systems (SEC401)

Example: Induction

if (x>=0 && y>=0) {

r=0;

i=y;

while(i>0) {

i>0 condition: r==(y-i)*x && i>=0

i’=i-1

r’=r+x

post condition: r’==(y-i’)*x && i’>=0

}

assert(r==x*y);

}

x,y,r,i,r’,i’

A

Now we ignore how

we got into the loop

Inductive check

Page 65: AWS re:Invent 2016: Automated Formal Reasoning About AWS Systems (SEC401)

Example: Induction

if (x>=0 && y>=0) {

r=0;

i=y;

while(i>0) {

pre condition: r==(y-i)*x && i>=0

i--;

r=r+x;

post condition: r==(y-i)*x && i>=0

}

assert(r==x*y);

}

Page 66: AWS re:Invent 2016: Automated Formal Reasoning About AWS Systems (SEC401)

Example: Induction

if (x>=0 && y>=0) {

r=0;

i=y;

while(i>0) {

pre condition: r==(y-i)*x && i>=0

i--;

r=r+x;

post condition: r==(y-i)*x && i>=0

}

assert(r==x*y);

}

Page 67: AWS re:Invent 2016: Automated Formal Reasoning About AWS Systems (SEC401)

Example: Induction

if (x>=0 && y>=0) {

r=0;

i=y;

while(i>0) {

pre condition: r==(y-i)*x && i>=0

i--;

r=r+x;

post condition: r==(y-i)*x && i>=0

}

assert(r==x*y);

}

Page 68: AWS re:Invent 2016: Automated Formal Reasoning About AWS Systems (SEC401)

Example: Induction

if (x>=0 && y>=0) {

r=0;

i=y;

while(i>0) {

pre condition: r==(y-i)*x && i>=0

i--;

r=r+x;

post condition: r==(y-i)*x && i>=0

}

assert(r==x*y);

}

If you have good heuristics

for guessing the inductive

invariant, the undecidable

feels decidable

Page 69: AWS re:Invent 2016: Automated Formal Reasoning About AWS Systems (SEC401)

Example: Induction

if (x>=0 && y>=0) {

r=0;

i=y;

while(i>0) {

pre condition: r==(y-i)*x && i>=0

i--;

r=r+x;

post condition: r==(y-i)*x && i>=0

}

assert(r==x*y);

}

This type of bookkeeping can

be dealt with using previously

discussed techniques for NP-

complete problems

Page 70: AWS re:Invent 2016: Automated Formal Reasoning About AWS Systems (SEC401)

Core ideas behind the advances/buzzwords

• Making NP-complete problems feel P-time in practice

• Conflict-clause driven learning

• Back-jumping

• Random-restarts

• SAT and SAT modulo theories

• Making undecidable problems feel decidable in practice

• Abstraction to finite/tractable problems

• Counterexample-guided abstraction refinement

• Interpolation for guessing inductive invariants

Page 71: AWS re:Invent 2016: Automated Formal Reasoning About AWS Systems (SEC401)

Questions answered in this talk

• What is “Mechanized reasoning in mathematical logic” ?

• What are some examples of what is AWS doing in this space?

Page 72: AWS re:Invent 2016: Automated Formal Reasoning About AWS Systems (SEC401)

Questions answered in this talk

• What is “Mechanized reasoning in mathematical logic” ?

• What are some examples of what is AWS doing in this space?

Page 73: AWS re:Invent 2016: Automated Formal Reasoning About AWS Systems (SEC401)

Shared security model

• Securing the cloud

• “How do we know that the AWS crypto primitives are correctly

implemented and not vulnerable to side-channel attacks?”

• “How do we know that the Amazon EC2 virtualization layer protects

against memory corruption-based attacks?”

• Secure usage

• “Could my AWS IAM policy allow unintended users access to my S3

bucket?”

• “Am I only allowing one instance in my VPC to send outgoing

network packets?”

Page 74: AWS re:Invent 2016: Automated Formal Reasoning About AWS Systems (SEC401)

Shared security model

• Helping customers be secure in the cloud

• “Could my IAM policy allow unintended users access to my Amazon

S3 bucket?”

• “Am I allowing only one instance in my VPC to send outgoing

network packets?”

• Securing the cloud

• “How do we know that the AWS crypto primitives are correctly

implemented?”

• “How do we know that the Amazon EC2 virtualization layer protects

against memory corruption based attacks?”

Page 75: AWS re:Invent 2016: Automated Formal Reasoning About AWS Systems (SEC401)

Shared security model

• Helping customers be secure in the cloud

• “Could my IAM policy allow unintended users access to my Amazon

S3 bucket?”

• “Am I allowing only one instance in my VPC to send outgoing

network packets?”

• Securing the cloud

• “How do we know that the AWS crypto primitives are correctly

implemented?”

• “How do we know that the Amazon EC2 virtualization layer protects

against memory corruption-based attacks?”

Demo: tool for reasoning

about VPCs using

techniques for NP-complete

reasoning

Page 76: AWS re:Invent 2016: Automated Formal Reasoning About AWS Systems (SEC401)

Shared security model

• Helping customers be secure in the cloud

• “Could my IAM policy allow unintended users access to my Amazon

S3 bucket?”

• “Am I allowing only one instance in my VPC to send outgoing

network packets?”

• Securing the cloud

• “How do we know that the AWS crypto primitives are correctly

implemented?”

• “How do we know that the Amazon EC2 virtualization layer protects

against memory corruption-based attacks?”

Demo: tool for reasoning

about VPCs using

techniques for NP-complete

reasoning

Page 77: AWS re:Invent 2016: Automated Formal Reasoning About AWS Systems (SEC401)

Shared security model

• Helping customers be secure in the cloud

• “Could my IAM policy allow unintended users access to my Amazon

S3 bucket?”

• “Am I allowing only one instance in my VPC to send outgoing

network packets?”

• Securing the cloud

• “How do we know that the AWS crypto primitives are correctly

implemented?”

• “How do we know that the Amazon EC2 virtualization layer protects

against memory corruption-based attacks?”

Demo: Proving correctness

properties of s2n using

induction and techniques

for NP-complete reasoning

Page 78: AWS re:Invent 2016: Automated Formal Reasoning About AWS Systems (SEC401)

Shared security model

Demo: tool for reasoning

about VPCs using

techniques for NP-complete

reasoning

Page 79: AWS re:Invent 2016: Automated Formal Reasoning About AWS Systems (SEC401)

Reasoning about networks

• Web service and CLI available in private beta

• Automatically answers queries about customer EC2

networking configurations

• Queries written in a simple query language

• No packets sent; network not actually used

• We can reason about networks that have not been deployed yet

Page 80: AWS re:Invent 2016: Automated Formal Reasoning About AWS Systems (SEC401)

Reasoning about networks

• EC2 networking semantics specified in logic

• For example, all possible subtle interactions between NAT

gateways, AZs, ACLs, VPC peering endpoints, load balancers,

etc

• Considers all possible cases/scenarios

• Can prove that there is no way for instance I to reach J

• NP-complete queries, usually answered in P-time

• Using approaches mentioned previously

Page 81: AWS re:Invent 2016: Automated Formal Reasoning About AWS Systems (SEC401)

Example queries

• “Which EC2 instances are accessible from the Internet?”

• “From my VPC, can non-bastion instances only SSH to

the bastions?”

• “Which EC2 instances can access an S3 endpoint?”

• “Can instances tagged Public communicate with instances

tagged Private?"

Page 82: AWS re:Invent 2016: Automated Formal Reasoning About AWS Systems (SEC401)

Example queries

• “Which EC2 instances are accessible from the Internet?”

• “From my VPC, can non-bastion instances only SSH to

the bastions?”

• “Which EC2 instances can access an S3 endpoint?”

• “Can instances tagged Public communicate with instances

tagged Private?"

list: internet-can-ssh-to-instance(Inst).

Page 83: AWS re:Invent 2016: Automated Formal Reasoning About AWS Systems (SEC401)

Example queries

• “Which EC2 instances are accessible from the Internet?”

• “From my VPC, can non-bastion instances only SSH to

the bastions?”

• “Which EC2 instances can access an S3 endpoint?”

• “Can instances tagged Public communicate with instances

tagged Private?"

all Src, Dst:

instance-has-vpc(Src,byron_vpc) &&

!atom/instance-tag(Dst, tag-key/Name, tag-value/Bastion) &&

instance-can-ssh-to-instance(Src,Dst)

=>

atom/instance-tag(Dst,tag-key/Name,tag-value/Bastion)

Page 84: AWS re:Invent 2016: Automated Formal Reasoning About AWS Systems (SEC401)

Example queries

• “Which EC2 instances are accessible from the Internet?”

• “From my VPC, can non-bastion instances only SSH to

the bastions?”

• “Which EC2 instances can access an S3 endpoint?”

• “Can instances tagged Public communicate with instances

tagged Private?"

list:

ex Src:

instance-can-ssh-to-instance(Src,Dst) &&

atom/instance-tag(InstDest, tag-key/Name, tag-value/S3Endpoint)

Page 85: AWS re:Invent 2016: Automated Formal Reasoning About AWS Systems (SEC401)

Example queries

• “Which EC2 instances are accessible from the Internet?”

• “From my VPC, can non-bastion instances only SSH to

the bastions?”

• “Which EC2 instances can access an S3 endpoint?”

• “Can instances tagged Public communicate with instances

tagged Private?"

list:

ex Src:

instance-can-ssh-to-instance(Src,Dst) &&

atom/instance-tag(InstDest, tag-key/Name, tag-value/S3Endpoint)

Page 86: AWS re:Invent 2016: Automated Formal Reasoning About AWS Systems (SEC401)

EC2 networking concepts supported

Availability Zones

Instances

Internet gateways

Load balancers

NAT instances

NAT gateways

Network ACLs

Network interfaces

Regions

Route tables

Security groups

Subnets

Tags

VPC endpoints

VPC peering connections

VPCs

Page 87: AWS re:Invent 2016: Automated Formal Reasoning About AWS Systems (SEC401)
Page 88: AWS re:Invent 2016: Automated Formal Reasoning About AWS Systems (SEC401)
Page 89: AWS re:Invent 2016: Automated Formal Reasoning About AWS Systems (SEC401)

Shared security model

• Helping customers be secure in the cloud

• “Could my IAM policy allow unintended users access to my Amazon

S3 bucket?”

• “Am I allowing only one instance in my VPC to send outgoing

network packets?”

• Securing the cloud

• “How do we know that the AWS crypto primitives are correctly

implemented?”

• “How do we know that the Amazon EC2 virtualization layer protects

against memory corruption-based attacks?”

Page 90: AWS re:Invent 2016: Automated Formal Reasoning About AWS Systems (SEC401)

Shared security model

• Helping customers be secure in the cloud

• “Could my IAM policy allow unintended users access to my Amazon

S3 bucket?”

• “Am I allowing only one instance in my VPC to send outgoing

network packets?”

• Securing the cloud

• “How do we know that the AWS crypto primitives are correctly

implemented?”

• “How do we know that the Amazon EC2 virtualization layer protects

against memory corruption-based attacks?”

Demo: Proving correctness

properties of s2n using

induction and techniques

for NP-complete reasoning

Page 91: AWS re:Invent 2016: Automated Formal Reasoning About AWS Systems (SEC401)

Shared security model

Demo: Proving correctness

properties of s2n using

induction and techniques

for NP-complete reasoning

Page 92: AWS re:Invent 2016: Automated Formal Reasoning About AWS Systems (SEC401)

S2N

• Small, fast TLS library

• Rigorously engineered for security

• Open source

• Mechanical reasoning:

• Automated proving of correctness of S2N’s HMAC implementation

• Proof performed in SAW, see https://saw.galois.com

• Proof strategy: NP-complete techniques + Induction

• Continuous integration: s2n is re-proved correct at each code

checkin

Page 93: AWS re:Invent 2016: Automated Formal Reasoning About AWS Systems (SEC401)

HMAC

• Keyed-hash message authentication code

• Provides a signature for a message that confirms:• Authenticity: the message was signed by the expected sender

• Integrity: the message has not been modified

HMAC(K, m) = H((K0 ⊕ opad)‖H((K0 ⊕ ipad)‖m))

Page 94: AWS re:Invent 2016: Automated Formal Reasoning About AWS Systems (SEC401)

HMAC

• Keyed-hash message authentication code

• Provides a signature for a message that confirms:• Authenticity: the message was signed by the expected sender

• Integrity: the message has not been modified

HMAC(K, m) = H((K0 ⊕ opad)‖H((K0 ⊕ ipad)‖m))

message

Page 95: AWS re:Invent 2016: Automated Formal Reasoning About AWS Systems (SEC401)

HMAC

• Keyed-hash message authentication code

• Provides a signature for a message that confirms:• Authenticity: the message was signed by the expected sender

• Integrity: the message has not been modified

HMAC(K, m) = H((K0⊕ opad)‖H((K0⊕ ipad)‖m))

derived from key

Page 96: AWS re:Invent 2016: Automated Formal Reasoning About AWS Systems (SEC401)

HMAC

• Keyed-hash message authentication code

• Provides a signature for a message that confirms:• Authenticity: the message was signed by the expected sender

• Integrity: the message has not been modified

HMAC(K, m) = H((K0⊕ opad)‖H((K0⊕ ipad)‖m))

arbitrary hash function

Page 97: AWS re:Invent 2016: Automated Formal Reasoning About AWS Systems (SEC401)

HMAC

• Keyed-hash message authentication code

• Provides a signature for a message that confirms:• Authenticity: the message was signed by the expected sender

• Integrity: the message has not been modified

HMAC(K, m) = H((K0⊕ opad)‖H((K0⊕ ipad)‖m))

constants from NIST

Page 98: AWS re:Invent 2016: Automated Formal Reasoning About AWS Systems (SEC401)

HMAC

hmac h h2 h3 K m = h2 (okey # split (h (ikey # m)))

where

k0 = kinit h3 K

okey = [kb ^ 0x5C | kb <- k0]

ikey = [kb ^ 0x36 | kb <- k0]

HMAC(K, m) = H((K0⊕ opad)‖H((K0⊕ ipad)‖m))

Cryptol formal specification:

Page 99: AWS re:Invent 2016: Automated Formal Reasoning About AWS Systems (SEC401)

HMAC

hmac h h2 h3 K m = h2 (okey # split (h (ikey # m)))

where

k0 = kinit h3 K

okey = [kb ^ 0x5C | kb <- k0]

ikey = [kb ^ 0x36 | kb <- k0]

HMAC(K, m) = H((K0⊕ opad)‖H((K0⊕ ipad)‖m))

Cryptol formal specification:

Page 100: AWS re:Invent 2016: Automated Formal Reasoning About AWS Systems (SEC401)

hmac h h2 h3 K m =

h2 (okey # split (h (ikey # m)))

where

k0 = kinit h3 K

okey = [kb ^ 0x5C | kb <- k0]

ikey = [kb ^ 0x36 | kb <- k0]

static int s2n_sslv3_mac_init (struct s2n_hmac_state *state,

s2n_hmac_algorithm alg, const void *key,

uint32_t klen)

{

s2n_hash_algorithm hash_alg = S2N_HASH_NONE ;

if (alg == S2N_HMAC_SSLv3_MD5 ) {

hash_alg = S2N_HASH_MD5 ;

}

if (alg == S2N_HMAC_SSLv3_SHA1 ) {

hash_alg = S2N_HASH_SHA1 ;

}

for (int i = 0; i < state->block_size; i++) {

state->xor_pad[i] = 0x36;

}

GUARD(s2n_hash_init (&state->inner_just_key , hash_alg));

GUARD(s2n_hash_update (&state->inner_just_key , key, klen));

GUARD(s2n_hash_update (&state->inner_just_key , state->xor_pad,

state->block_size));

for (int i = 0; i < state->block_size; i++) {

state->xor_pad[i] = 0x5c;

}

GUARD(s2n_hash_init (&state->outer, hash_alg));

GUARD(s2n_hash_update (&state->outer, key, klen));

GUARD(s2n_hash_update (&state->outer, state->xor_pad, state->block_size));

/* Copy inner_just_key to inner */

return s2n_hmac_reset (state);

}

static int s2n_sslv3_mac_digest (struct s2n_hmac_state *state, void *out,

uint32_t size)

{

for (int i = 0; i < state->block_size; i++) {

state->xor_pad[i] = 0x5c;

}

GUARD(s2n_hash_digest (&state->inner, state->digest_pad,

state->digest_size ));

memcpy_check (&state->inner, &state->outer, sizeof(state->inner));

GUARD(s2n_hash_update (&state->inner, state->digest_pad,

state->digest_size ));

return s2n_hash_digest (&state->inner, out, size);

}

int s2n_hmac_init (struct s2n_hmac_state *state, s2n_hmac_algorithm alg,

const void *key, uint32_t klen)

{

s2n_hash_algorithm hash_alg = S2N_HASH_NONE ;

state->currently_in_hash_block = 0;

state->digest_size = 0;

state->block_size = 64;

state->hash_block_size = 64;

switch (alg) {

case S2N_HMAC_NONE :

break;

case S2N_HMAC_SSLv3_MD5 :

state->block_size = 48;

/* Fall through ... */

case S2N_HMAC_MD5 :

hash_alg = S2N_HASH_MD5 ;

state->digest_size = MD5_DIGEST_LENGTH ;

break;

case S2N_HMAC_SSLv3_SHA1 :

state->block_size = 40;

/* Fall through ... */

case S2N_HMAC_SHA1 :

hash_alg = S2N_HASH_SHA1 ;

state->digest_size = SHA_DIGEST_LENGTH ;

break;

case S2N_HMAC_SHA224 :

hash_alg = S2N_HASH_SHA224 ;

state->digest_size = SHA224_DIGEST_LENGTH ;

break;

case S2N_HMAC_SHA256 :

hash_alg = S2N_HASH_SHA256 ;

state->digest_size = SHA256_DIGEST_LENGTH ;

break;

case S2N_HMAC_SHA384 :

hash_alg = S2N_HASH_SHA384 ;

state->digest_size = SHA384_DIGEST_LENGTH ;

state->block_size = 128;

state->hash_block_size = 128;

break;

case S2N_HMAC_SHA512 :

hash_alg = S2N_HASH_SHA512 ;

state->digest_size = SHA512_DIGEST_LENGTH ;

state->block_size = 128;

state->hash_block_size = 128;

break;

default:

S2N_ERROR(S2N_ERR_HMAC_INVALID_ALGORITHM );

}

gte_check(sizeof(state->xor_pad), state->block_size);

gte_check(sizeof(state->digest_pad), state->digest_size );

state->alg = alg;

if (alg == S2N_HMAC_SSLv3_SHA1 || alg == S2N_HMAC_SSLv3_MD5 ) {

return s2n_sslv3_mac_init (state, alg, key, klen);

}

GUARD(s2n_hash_init (&state->inner_just_key , hash_alg));

GUARD(s2n_hash_init (&state->outer, hash_alg));

uint32_t copied = klen;

if (klen > state->block_size) {

GUARD(s2n_hash_update (&state->outer, key, klen));

GUARD(s2n_hash_digest (&state->outer, state->digest_pad,

state->digest_size));

memcpy_check(state->xor_pad, state->digest_pad, state->digest_size);

copied = state->digest_size;

} else {

memcpy_check(state->xor_pad, key, klen);

}

for (int i = 0; i < copied; i++) {

state->xor_pad[i] ^= 0x36;

}

for (int i = copied; i < state->block_size; i++) {

state->xor_pad[i] = 0x36;

}

GUARD(s2n_hash_update (&state->inner_just_key , state->xor_pad,

state->block_size));

/* 0x36 xor 0x5c == 0x6a */

for (int i = 0; i < state->block_size; i++) {

state->xor_pad[i] ^= 0x6a;

}

return s2n_hmac_reset (state);

}

int s2n_hmac_update (struct s2n_hmac_state *state, const void *in, uint32_t size)

{

/* Keep track of how much of the current hash block is full

*

* Why the 4294949760 constant in this code? 4294949760 is the

* highest 32-bit value that is congruent to 0 modulo all of our

* HMAC block sizes, that is also at least 16k smaller than 2^32. It

* therefore has no effect on the mathematical result, and no valid

* record size can cause it to overflow.

*

* The value was found with the following python code;

*

* x = (2 ** 32) - (2 ** 14)

* while True:

* if x % 40 | x % 48 | x % 64 | x % 128 == 0:

* break

* x -= 1

* print x

*

* What it does do however is ensure that the mod operation takes a

* constant number of instruction cycles, regardless of the size of

* the input. On some platforms, including Intel, the operation can

* take a smaller number of cycles if the input is "small".

*/

state->currently_in_hash_block += (4294949760 + size) % state->hash_block_size ;

state->currently_in_hash_block %= state->block_size;

return s2n_hash_update (&state->inner, in, size);

}

int s2n_hmac_digest (struct s2n_hmac_state *state, void *out, uint32_t size)

{

if (state->alg == S2N_HMAC_SSLv3_SHA1 || state->alg == S2N_HMAC_SSLv3_MD5 ) {

return s2n_sslv3_mac_digest (state, out, size);

}

GUARD(s2n_hash_digest (&state->inner, state->digest_pad,

state->digest_size ));

GUARD(s2n_hash_reset (&state->outer));

GUARD(s2n_hash_update (&state->outer, state->xor_pad, state->block_size));

GUARD(s2n_hash_update (&state->outer, state->digest_pad,

state->digest_size ));

return s2n_hash_digest (&state->outer, out, size);

}

int s2n_hmac_reset (struct s2n_hmac_state *state)

{

state->currently_in_hash_block = 0;

memcpy_check (&state->inner, &state->inner_just_key , sizeof(state->inner));

return 0;

}

static int s2n_sslv3_mac_init (struct s2n_hmac_state *state,

s2n_hmac_algorithm alg, const void *key,

uint32_t klen)

{

s2n_hash_algorithm hash_alg = S2N_HASH_NONE ;

if (alg == S2N_HMAC_SSLv3_MD5 ) {

hash_alg = S2N_HASH_MD5 ;

}

if (alg == S2N_HMAC_SSLv3_SHA1 ) {

hash_alg = S2N_HASH_SHA1 ;

}

for (int i = 0; i < state->block_size; i++) {

state->xor_pad[i] = 0x36;

}

GUARD(s2n_hash_init (&state->inner_just_key , hash_alg));

GUARD(s2n_hash_update (&state->inner_just_key , key, klen));

GUARD(s2n_hash_update (&state->inner_just_key , state->xor_pad,

state->block_size));

for (int i = 0; i < state->block_size; i++) {

state->xor_pad[i] = 0x5c;

}

GUARD(s2n_hash_init (&state->outer, hash_alg));

GUARD(s2n_hash_update (&state->outer, key, klen));

GUARD(s2n_hash_update (&state->outer, state->xor_pad, state->block_size));

/* Copy inner_just_key to inner */

return s2n_hmac_reset (state);

}

static int s2n_sslv3_mac_digest (struct s2n_hmac_state *state, void *out,

uint32_t size)

{

for (int i = 0; i < state->block_size; i++) {

state->xor_pad[i] = 0x5c;

}

GUARD(s2n_hash_digest (&state->inner, state->digest_pad,

state->digest_size ));

memcpy_check (&state->inner, &state->outer, sizeof(state->inner));

GUARD(s2n_hash_update (&state->inner, state->digest_pad,

state->digest_size ));

return s2n_hash_digest (&state->inner, out, size);

}

int s2n_hmac_init (struct s2n_hmac_state *state, s2n_hmac_algorithm alg,

const void *key, uint32_t klen)

{

s2n_hash_algorithm hash_alg = S2N_HASH_NONE ;

state->currently_in_hash_block = 0;

state->digest_size = 0;

state->block_size = 64;

state->hash_block_size = 64;

switch (alg) {

case S2N_HMAC_NONE :

break;

case S2N_HMAC_SSLv3_MD5 :

state->block_size = 48;

/* Fall through ... */

case S2N_HMAC_MD5 :

hash_alg = S2N_HASH_MD5 ;

state->digest_size = MD5_DIGEST_LENGTH ;

break;

case S2N_HMAC_SSLv3_SHA1 :

state->block_size = 40;

/* Fall through ... */

case S2N_HMAC_SHA1 :

hash_alg = S2N_HASH_SHA1 ;

state->digest_size = SHA_DIGEST_LENGTH ;

break;

case S2N_HMAC_SHA224 :

hash_alg = S2N_HASH_SHA224 ;

state->digest_size = SHA224_DIGEST_LENGTH ;

break;

case S2N_HMAC_SHA256 :

hash_alg = S2N_HASH_SHA256 ;

state->digest_size = SHA256_DIGEST_LENGTH ;

break;

case S2N_HMAC_SHA384 :

hash_alg = S2N_HASH_SHA384 ;

state->digest_size = SHA384_DIGEST_LENGTH ;

state->block_size = 128;

state->hash_block_size = 128;

break;

case S2N_HMAC_SHA512 :

hash_alg = S2N_HASH_SHA512 ;

state->digest_size = SHA512_DIGEST_LENGTH ;

state->block_size = 128;

state->hash_block_size = 128;

break;

default:

S2N_ERROR(S2N_ERR_HMAC_INVALID_ALGORITHM );

}

gte_check(sizeof(state->xor_pad), state->block_size);

gte_check(sizeof(state->digest_pad), state->digest_size );

state->alg = alg;

if (alg == S2N_HMAC_SSLv3_SHA1 || alg == S2N_HMAC_SSLv3_MD5 ) {

return s2n_sslv3_mac_init (state, alg, key, klen);

}

GUARD(s2n_hash_init (&state->inner_just_key , hash_alg));

GUARD(s2n_hash_init (&state->outer, hash_alg));

uint32_t copied = klen;

if (klen > state->block_size) {

GUARD(s2n_hash_update (&state->outer, key, klen));

GUARD(s2n_hash_digest (&state->outer, state->digest_pad,

state->digest_size));

memcpy_check(state->xor_pad, state->digest_pad, state->digest_size);

copied = state->digest_size;

} else {

memcpy_check(state->xor_pad, key, klen);

}

for (int i = 0; i < copied; i++) {

state->xor_pad[i] ^= 0x36;

}

for (int i = copied; i < state->block_size; i++) {

state->xor_pad[i] = 0x36;

}

GUARD(s2n_hash_update (&state->inner_just_key , state->xor_pad,

state->block_size));

/* 0x36 xor 0x5c == 0x6a */

for (int i = 0; i < state->block_size; i++) {

state->xor_pad[i] ^= 0x6a;

}

return s2n_hmac_reset (state);

}

int s2n_hmac_update (struct s2n_hmac_state *state, const void *in, uint32_t size)

{

/* Keep track of how much of the current hash block is full

*

* Why the 4294949760 constant in this code? 4294949760 is the

* highest 32-bit value that is congruent to 0 modulo all of our

* HMAC block sizes, that is also at least 16k smaller than 2^32. It

* therefore has no effect on the mathematical result, and no valid

* record size can cause it to overflow.

*

* The value was found with the following python code;

*

* x = (2 ** 32) - (2 ** 14)

* while True:

* if x % 40 | x % 48 | x % 64 | x % 128 == 0:

* break

* x -= 1

* print x

*

* What it does do however is ensure that the mod operation takes a

* constant number of instruction cycles, regardless of the size of

* the input. On some platforms, including Intel, the operation can

* take a smaller number of cycles if the input is "small".

*/

state->currently_in_hash_block += (4294949760 + size) % state->hash_block_size ;

state->currently_in_hash_block %= state->block_size;

return s2n_hash_update (&state->inner, in, size);

}

int s2n_hmac_digest (struct s2n_hmac_state *state, void *out, uint32_t size)

{

if (state->alg == S2N_HMAC_SSLv3_SHA1 || state->alg == S2N_HMAC_SSLv3_MD5 ) {

return s2n_sslv3_mac_digest (state, out, size);

}

GUARD(s2n_hash_digest (&state->inner, state->digest_pad,

state->digest_size ));

GUARD(s2n_hash_reset (&state->outer));

GUARD(s2n_hash_update (&state->outer, state->xor_pad, state->block_size));

GUARD(s2n_hash_update (&state->outer, state->digest_pad,

state->digest_size ));

return s2n_hash_digest (&state->outer, out, size);

}

int s2n_hmac_reset (struct s2n_hmac_state *state)

{

state->currently_in_hash_block = 0;

memcpy_check (&state->inner, &state->inner_just_key , sizeof(state->inner));

return 0;

}

C HMACCryptol HMAC

Proof bridges this gap

Page 101: AWS re:Invent 2016: Automated Formal Reasoning About AWS Systems (SEC401)

Intermediate model

High-level

Cryptol

Code

Lower-level

Cryptol

Code

Production

s2n

codeproof proof

”Proof plumbing”: hand-crafted

proof artifact written in Galois

language

Page 102: AWS re:Invent 2016: Automated Formal Reasoning About AWS Systems (SEC401)

Intermediate model

High-level

Cryptol

code

Lower-level

Cryptol

code

Production

s2n

codeproof proof

Incorporates s2n data

structures and APIs

Page 103: AWS re:Invent 2016: Automated Formal Reasoning About AWS Systems (SEC401)

Intermediate model

High-level

Cryptol

Code

Lower-level

Cryptol

Code

Production

s2n

codeproof proof

Omits pointer/memory and low-

level performance optimizations

Page 104: AWS re:Invent 2016: Automated Formal Reasoning About AWS Systems (SEC401)

Comparing for all message sizes and splittings

• Key inductive lemmas:• hmac_update(hmac_update(s,m1),m2)) =

hmac_update(s,m1#m2)

• hmac_update(s, ””) = s

• Proved:

• Any sequence of hmac_update calls equivalent to a single call

• Single call of specification hmac_update equivalent to

implementation hmac_update

Page 105: AWS re:Invent 2016: Automated Formal Reasoning About AWS Systems (SEC401)

Continuous integration

• Proofs replayed automatically in Travis CI• Proof failure is a build failure

• Average runtime: 15mins

• Proof is agnostic to structure of C code, depends on:• Interfaces (arguments and struct layouts)

• Function call structure

• Easily adapted:• Function body changes → no proof changes likely needed

• Interface changes → similarly sized proof changes

• Call structure changes → tiny proof changes

Page 106: AWS re:Invent 2016: Automated Formal Reasoning About AWS Systems (SEC401)
Page 107: AWS re:Invent 2016: Automated Formal Reasoning About AWS Systems (SEC401)

Demo

Page 108: AWS re:Invent 2016: Automated Formal Reasoning About AWS Systems (SEC401)

Questions answered in this talk

• What is “Mechanized reasoning in mathematical logic” ?

• What are some examples of what is AWS doing in this space?

Page 109: AWS re:Invent 2016: Automated Formal Reasoning About AWS Systems (SEC401)

Questions answered in this talk

• What is “Mechanized reasoning in mathematical logic” ?

• What are some examples of what is AWS doing in this space?

Page 110: AWS re:Invent 2016: Automated Formal Reasoning About AWS Systems (SEC401)

Shared security model

• Securing the cloud

• “How do we know that the AWS crypto primitives are correctly

implemented and not vulnerable to side-channel attacks?”

• “How do we know that the Amazon EC2 virtualization layer protects

against memory corruption-based attacks?”

• Secure usage

• “Could my AWS IAM policy allow unintended users access to my S3

bucket?”

• “Am I only allowing one instance in my VPC to send outgoing

network packets?”

Page 111: AWS re:Invent 2016: Automated Formal Reasoning About AWS Systems (SEC401)

Shared security model

• Helping customers be secure in the cloud

• “Could my IAM policy allow unintended users access to my Amazon

S3 bucket?”

• “Am I allowing only one instance in my VPC to send outgoing

network packets?”

• Securing the cloud

• “How do we know that the AWS crypto primitives are correctly

implemented?”

• “How do we know that the Amazon EC2 virtualization layer protects

against memory corruption-based attacks?”

Page 112: AWS re:Invent 2016: Automated Formal Reasoning About AWS Systems (SEC401)

Shared security model

• Helping customers be secure in the cloud

• “Could my IAM policy allow unintended users access to my Amazon

S3 bucket?”

• “Am I allowing only one instance in my VPC to send outgoing

network packets?”

• Securing the cloud

• “How do we know that the AWS crypto primitives are correctly

implemented?”

• “How do we know that the Amazon EC2 virtualization layer protects

against memory corruption-based attacks?”

Project addressing this topic

too

Page 113: AWS re:Invent 2016: Automated Formal Reasoning About AWS Systems (SEC401)

Shared security model

• Helping customers be secure in the cloud

• “Could my AWS IAM policy allow unintended users access to my S3

bucket?”

• “Am I allowing only one instance in my VPC to send outgoing

network packets?”

• Securing the cloud

• “How do we know that the AWS crypto primitives are correctly

implemented?”

• “How do we know that the Amazon EC2 virtualization layer protects

against memory corruption-based attacks?”

Project addressing this topic

too

Page 114: AWS re:Invent 2016: Automated Formal Reasoning About AWS Systems (SEC401)

Thank you!