toward semantic cryptography apiscybersec-prod.s3.amazonaws.com/secdev/wp-content/... · 4 tips for...

30
Toward Semantic Cryptography APIs Tudor Dumitraș Assistant Professor, ECE & MC2 University of Maryland, College Park Work with Soumya Indela, Mukul Kulkarni, and Kartik Nayak (UMD)

Upload: others

Post on 19-Jul-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Toward Semantic Cryptography APIscybersec-prod.s3.amazonaws.com/secdev/wp-content/... · 4 Tips for Better Crypto Code 1. Don’t expect too much from simplified APIs and secure defaults

Toward Semantic Cryptography APIs

Tudor Dumitraș

Assistant Professor, ECE & MC2 University of Maryland, College Park

Work with Soumya Indela, Mukul Kulkarni, and Kartik Nayak (UMD)

Page 2: Toward Semantic Cryptography APIscybersec-prod.s3.amazonaws.com/secdev/wp-content/... · 4 Tips for Better Crypto Code 1. Don’t expect too much from simplified APIs and secure defaults

Why Johnny Developer Can’t Encrypt?

• User mistakes in using cryptography – Why Johnny Can’t Encrypt: A Usability Evaluation of PGP 5.0

[Witten & Tygar, 1999]

– Stimulated usability research in security

• Developer mistakes in using cryptography [Georgiev+, 2012; Egele+, 2013; Fahl+, 2013; Reaves+, 2015]

– Examples of mistakes • Insecure parameters (ECB mode, constant encryption keys)

• No authentication (e.g. incorrect SSL certificate validation)

• DIY crypto

– Severe impact • Leak of personal information (e.g. financial data), can steal money!

T. Dumitraș :: Toward Semantic Cryptography APIs 2

Page 3: Toward Semantic Cryptography APIscybersec-prod.s3.amazonaws.com/secdev/wp-content/... · 4 Tips for Better Crypto Code 1. Don’t expect too much from simplified APIs and secure defaults

Can you find a bug?

Establishing a secure SSL connection (code from Python documentation)

import socket, ssl

context = ssl.SSLContext(ssl.PROTOCOL_TLSv1)

context.verify_mode = ssl.CERT_REQUIRED

context.load_default_certs()

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

ssl_sock = context.wrap_socket(s, server_hostname='www.verisign.com')

ssl_sock.connect(('www.verisign.com', 443))

T. Dumitraș :: Toward Semantic Cryptography APIs 3

(1) Client “hello” Cryptographic Information

Server “hello” (2) Server Certificate

(3) Validate Server Certificate

(4) Establish connection

Tud0rCanD3crypt

Attacks on SSL protocol (e.g. Freak,

Logjam): out of scope

[https://docs.python.org/2/library/ssl.html]

Page 4: Toward Semantic Cryptography APIscybersec-prod.s3.amazonaws.com/secdev/wp-content/... · 4 Tips for Better Crypto Code 1. Don’t expect too much from simplified APIs and secure defaults

Examples of Crypto Mistakes

import socket, ssl

context = ssl.SSLContext(ssl.PROTOCOL_TLSv1)

context.verify_mode = ssl.CERT_REQUIRED

context.load_default_certs()

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

ssl_sock = context.wrap_socket(s, server_hostname='www.verisign.com')

ssl_sock.connect(('www.verisign.com', 443))

T. Dumitraș :: Toward Semantic Cryptography APIs 4

Tud0rCanD3crypt: I’ll send a valid cert for Tudorz0wn.com (or a

self-signed cert)!

[https://docs.python.org/2/library/ssl.html]

Page 5: Toward Semantic Cryptography APIscybersec-prod.s3.amazonaws.com/secdev/wp-content/... · 4 Tips for Better Crypto Code 1. Don’t expect too much from simplified APIs and secure defaults

Examples of Crypto Mistakes – cont’d

import socket, ssl

context = ssl.SSLContext(ssl.PROTOCOL_TLSv1)

context.verify_mode = ssl.CERT_REQUIRED

context.check_hostname = True

context.load_default_certs()

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

ssl_sock = context.wrap_socket(s, server_hostname='www.verisign.com')

ssl_sock.connect(('www.verisign.com', 443))

T. Dumitraș :: Toward Semantic Cryptography APIs 5

Tud0rCanD3crypt: I’ll send a cert I’ve

hacked through Heartbleed)!

[https://docs.python.org/2/library/ssl.html]

Page 6: Toward Semantic Cryptography APIscybersec-prod.s3.amazonaws.com/secdev/wp-content/... · 4 Tips for Better Crypto Code 1. Don’t expect too much from simplified APIs and secure defaults

Examples of Crypto Mistakes – cont’d

import socket, ssl

context = ssl.SSLContext(ssl.PROTOCOL_TLSv1)

context.verify_mode = ssl.CERT_REQUIRED

context.check_hostname = True

context.load_default_certs()

context.verify_flags = ssl.VERIFY_CRL_CHECK_LEAF

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

ssl_sock = context.wrap_socket(s, server_hostname='www.verisign.com')

ssl_sock.connect(('www.verisign.com', 443))

T. Dumitraș :: Toward Semantic Cryptography APIs 6

Tud0rCanD3crypt: I’ll send an unrevoked cert

issued by DigiNotar!

[https://docs.python.org/2/library/ssl.html]

Page 7: Toward Semantic Cryptography APIscybersec-prod.s3.amazonaws.com/secdev/wp-content/... · 4 Tips for Better Crypto Code 1. Don’t expect too much from simplified APIs and secure defaults

Examples of Crypto Mistakes – cont’d

import socket, ssl

context = ssl.SSLContext(ssl.PROTOCOL_TLSv1)

context.verify_mode = ssl.CERT_REQUIRED

context.check_hostname = True

context.load_default_certs()

context.verify_flags = ssl.VERIFY_CRL_CHECK_CHAIN

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

ssl_sock = context.wrap_socket(s, server_hostname='www.verisign.com')

ssl_sock.connect(('www.verisign.com', 443))

T. Dumitraș :: Toward Semantic Cryptography APIs 7

[https://docs.python.org/2/library/ssl.html]

Page 8: Toward Semantic Cryptography APIscybersec-prod.s3.amazonaws.com/secdev/wp-content/... · 4 Tips for Better Crypto Code 1. Don’t expect too much from simplified APIs and secure defaults

Summary of Problems

• Default parameters do not ensure security – Example: default certs

• Must perform additional security checks – Checks are sometimes disabled during development & testing

(e.g. self-signed certs)

• Security depends on external information – Example: certificate revocation status

• Need an understanding of attacks and defenses to use crypto APIs correctly – No separation of concerns

T. Dumitraș :: Toward Semantic Cryptography APIs 8

Page 9: Toward Semantic Cryptography APIscybersec-prod.s3.amazonaws.com/secdev/wp-content/... · 4 Tips for Better Crypto Code 1. Don’t expect too much from simplified APIs and secure defaults

4 Tips for Better Crypto Code

1. Don’t expect too much from simplified APIs and secure defaults

2. Provide a mechanism to integrate security-critical external information at runtime

3. Confine security decision to code components written by security engineers

4. Provide compile-time mechanisms to turn off security workarounds

T. Dumitraș :: Toward Semantic Cryptography APIs 9

Page 10: Toward Semantic Cryptography APIscybersec-prod.s3.amazonaws.com/secdev/wp-content/... · 4 Tips for Better Crypto Code 1. Don’t expect too much from simplified APIs and secure defaults

1. Secure Defaults and Simplified APIs

T. Dumitraș :: Toward Semantic Cryptography APIs 10

Page 11: Toward Semantic Cryptography APIscybersec-prod.s3.amazonaws.com/secdev/wp-content/... · 4 Tips for Better Crypto Code 1. Don’t expect too much from simplified APIs and secure defaults

Secure Defaults Are Insufficient

• Default values do not ensure security – ECB mode is default for AES in PyCrypto, Java JSSE and derived

Android libraries (CWE-326) – Uninitialized variables may be controlled by an adversary (CWE-

453)

• Default values may vary across libraries

$url = "https://example.com";

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $url);

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, TRUE);

curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, TRUE);

$data = curl_exec($ch);

curl_close($ch);

print_r($data);

T. Dumitraș :: Toward Semantic Cryptography APIs 11

curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2 );

Page 12: Toward Semantic Cryptography APIscybersec-prod.s3.amazonaws.com/secdev/wp-content/... · 4 Tips for Better Crypto Code 1. Don’t expect too much from simplified APIs and secure defaults

Developers Have Diverse Needs

• Various developer needs – Simple communication over the Internet

– Libraries for managing cloud resources

– Secure financial transactions

• Application specific choices – No consensus on best way to check for certificate revocations

[Liu+, 2015]

• Mobile browsers don’t check CRLs

• OCSP not widely adopted

• Developers must make security decisions – The simplified APIs adopted by recent crypto frameworks (e.g.

NaCL, cryptography.io) are insufficient

T. Dumitraș :: Toward Semantic Cryptography APIs 12

Page 13: Toward Semantic Cryptography APIscybersec-prod.s3.amazonaws.com/secdev/wp-content/... · 4 Tips for Better Crypto Code 1. Don’t expect too much from simplified APIs and secure defaults

2. Security Engineers vs. Functionality Engineers

T. Dumitraș :: Toward Semantic Cryptography APIs 13

Page 14: Toward Semantic Cryptography APIscybersec-prod.s3.amazonaws.com/secdev/wp-content/... · 4 Tips for Better Crypto Code 1. Don’t expect too much from simplified APIs and secure defaults

How to Use Crypto APIs Correctly?

• Need understanding of attacks and defenses – Common mistakes

• Accept expired certificates (CWE-298, CWE-324)

• Skip hostname verification (CWE-297, CWE-295)

• Store secret keys unencrypted (CWE-311, CWE-312)

• Use hard-coded keys (CWE-321, CWE-259)

• Need understanding of implementation – Hostname verification in JSSE: only if algorithm field is set

to “HTTPS”

– Expired certificate: handshake fail (IBM JSSE) vs. handshake succeeds (Oracle JSSE)

• Same Java code!

T. Dumitraș :: Toward Semantic Cryptography APIs 14

No Separation of Concerns!

Page 15: Toward Semantic Cryptography APIscybersec-prod.s3.amazonaws.com/secdev/wp-content/... · 4 Tips for Better Crypto Code 1. Don’t expect too much from simplified APIs and secure defaults

Semantic API

T. Dumitraș :: Toward Semantic Cryptography APIs 15

• Security Engineers: write security sensitive code

– Authentication and authorization

– Secure communication

– Secure storage

• Functionality Engineers: focus on application logic

– Use APIs that do not require security knowledge, e.g. secureSend()

• Encapsulate security decisions in code written by security engineers

Page 16: Toward Semantic Cryptography APIscybersec-prod.s3.amazonaws.com/secdev/wp-content/... · 4 Tips for Better Crypto Code 1. Don’t expect too much from simplified APIs and secure defaults

Decoupling Functionality and Security

T. Dumitraș :: Toward Semantic Cryptography APIs 16

AbstractMessage

isConfidential()

Communicate

connect() secureSend() send()

ConcreteMessage

isConfidential()

if (isConfidential (msg))

throw Exception(“Use

secureSend()!");

msg

// Send

send(msg1)

// Send msg securely

secureSend(msg2)

Functionality Security

Page 17: Toward Semantic Cryptography APIscybersec-prod.s3.amazonaws.com/secdev/wp-content/... · 4 Tips for Better Crypto Code 1. Don’t expect too much from simplified APIs and secure defaults

3. Integrating External Information

T. Dumitraș :: Toward Semantic Cryptography APIs 17

Page 18: Toward Semantic Cryptography APIscybersec-prod.s3.amazonaws.com/secdev/wp-content/... · 4 Tips for Better Crypto Code 1. Don’t expect too much from simplified APIs and secure defaults

Need for External Information

• Security depends on information external to the system

– Crypto libraries implement algorithms no longer secure • MD5 (CWE-327), SHA1 (CWE-759), DES (CWE-328),, …

– Some algorithm parameters are known to be insecure • ECB mode, small key sizes, …

– Accepting revoked certificates is a security threat (CWE-299)

• This information evolves over time

– In some cases the updates are frequent (e.g. certificate revocation)

T. Dumitraș :: Toward Semantic Cryptography APIs 18

Integrate external info at runtime

Page 19: Toward Semantic Cryptography APIscybersec-prod.s3.amazonaws.com/secdev/wp-content/... · 4 Tips for Better Crypto Code 1. Don’t expect too much from simplified APIs and secure defaults

Regulator Pattern

• Regulator pattern for integrating external security information – Push Model: receive updates periodically (e.g. CRLs) – Pull Model: request update when needed (e.g. OCSP) – Selective Pull Model: receive unforgeable info from server (e.g.

OCSP Stapling)

T. Dumitraș :: Toward Semantic Cryptography APIs 19

Server Regulator

Client Regulator

Client Server

External Info

push

pull

selective pull

Secure channel

Page 20: Toward Semantic Cryptography APIscybersec-prod.s3.amazonaws.com/secdev/wp-content/... · 4 Tips for Better Crypto Code 1. Don’t expect too much from simplified APIs and secure defaults

4. Managing Security Workarounds

T. Dumitraș :: Toward Semantic Cryptography APIs 20

Page 21: Toward Semantic Cryptography APIscybersec-prod.s3.amazonaws.com/secdev/wp-content/... · 4 Tips for Better Crypto Code 1. Don’t expect too much from simplified APIs and secure defaults

Need for Security Workarounds

• Security mechanisms prevent certain operations

– Cannot test all code paths

– Some functionality is developed before the key infrastructure is in place

• Programmers disable security checks during development and testing

– Some of these workarounds remain in the public release

– Example: Using self-signed certificates in production (CWE-296)

T. Dumitraș :: Toward Semantic Cryptography APIs 21

Need to manage security workarounds

Page 22: Toward Semantic Cryptography APIscybersec-prod.s3.amazonaws.com/secdev/wp-content/... · 4 Tips for Better Crypto Code 1. Don’t expect too much from simplified APIs and secure defaults

Compile-Time Workaround Management

• Security workaround management

– Isolate workarounds in code

– Disable them with compile-time switch

• Implementation

– Projects typically maintain separate debug and release build profiles

– May disable some checks in debug build

– Example: specify certificate store in Maven pom.xml • Debug store may use self-signed certificates

• Certificate stores populated by security engineers

T. Dumitraș :: Toward Semantic Cryptography APIs 22

Page 23: Toward Semantic Cryptography APIscybersec-prod.s3.amazonaws.com/secdev/wp-content/... · 4 Tips for Better Crypto Code 1. Don’t expect too much from simplified APIs and secure defaults

Alternative Approaches

• Restrict decision choice for developers

– Simplified cryptography APIs: keyczar, cryptography.io, OpenCCE, NaCL

• Prove certain security properties

– Static analysis and type systems [Hunt & Sands, 2006; van Delft+, 2015]

– Security API analysis [Anderson, Security Engineering], International Workshop on Analysis of Security APIs

• Follow best practices in API design [Bloch, 2006]

T. Dumitraș :: Toward Semantic Cryptography APIs 23

Page 24: Toward Semantic Cryptography APIscybersec-prod.s3.amazonaws.com/secdev/wp-content/... · 4 Tips for Better Crypto Code 1. Don’t expect too much from simplified APIs and secure defaults

Conclusion

• Developers need the flexibility to select the most appropriate implementation of a security mechanism

– Code organization: security vs. functionality engineers

• Security often depends on external information

– Regulator pattern to retrieve such information at runtime

• Security workarounds serve legitimate purpose

– Isolate them to development build environment with compile time checks

T. Dumitraș :: Toward Semantic Cryptography APIs 24

Page 25: Toward Semantic Cryptography APIscybersec-prod.s3.amazonaws.com/secdev/wp-content/... · 4 Tips for Better Crypto Code 1. Don’t expect too much from simplified APIs and secure defaults

Thank you!

T. Dumitraș :: Toward Semantic Cryptography APIs 25

Tudor Dumitraș

[email protected]

http://ter.ps/cryptoapi

@tudor_dumitras

Page 26: Toward Semantic Cryptography APIscybersec-prod.s3.amazonaws.com/secdev/wp-content/... · 4 Tips for Better Crypto Code 1. Don’t expect too much from simplified APIs and secure defaults

Backup Slides

T. Dumitraș :: Toward Semantic Cryptography APIs 26

Page 27: Toward Semantic Cryptography APIscybersec-prod.s3.amazonaws.com/secdev/wp-content/... · 4 Tips for Better Crypto Code 1. Don’t expect too much from simplified APIs and secure defaults

No Separation of Concerns

• Security specific knowledge is required

– Knowledge of algorithms for example setting “https” algorithm field in

JSSE?

– Knowledge that certificates should be verified back to the root CA

...

PKIXParameters params = new PKIXParameters(trustAnchor);

params.setRevocationEnabled(true);

params.addCertPathChecker(new

ExtendedKeyUsagePKIXCertPathChecker(clientAuth, newChain[0]));

...

T. Dumitraș :: Toward Semantic Cryptography APIs 27

Page 28: Toward Semantic Cryptography APIscybersec-prod.s3.amazonaws.com/secdev/wp-content/... · 4 Tips for Better Crypto Code 1. Don’t expect too much from simplified APIs and secure defaults

Need for External Information

• TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA

• TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA

• SSL_DHE_RSA_WITH_3DES_EDE_CBC_SHA

• SSL_DHE_DSS_WITH_3DES_EDE_CBC_SHA

• TLS_ECDHE_ECDSA_WITH_RC4_128_SHA

• TLS_ECDHE_RSA_WITH_RC4_128_SHA

• TLS_ECDH_RSA_WITH_RC4_128_SHA

• SSL_RSA_WITH_RC4_128_MD5

• TLS_EMPTY_RENEGOTIATION_INFO_SCSV

• TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA

T. Dumitraș :: Toward Semantic Cryptography APIs 28

• TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA

• TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA

• TLS_RSA_WITH_AES_128_CBC_SHA

• TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA

• TLS_ECDH_RSA_WITH_AES_128_CBC_SHA

• TLS_DHE_RSA_WITH_AES_128_CBC_SHA

• TLS_DHE_DSS_WITH_AES_128_CBC_SHA

• SSL_RSA_WITH_RC4_128_SHA

• TLS_ECDH_ECDSA_WITH_RC4_128_SHA

Comparing algorithms supported by a web browser

• SSL_DHE_DSS_WITH_3DES_EDE_CBC_SHA

• SSL_RSA_WITH_RC4_128_MD5

Thus, algorithms need to be updated

Page 29: Toward Semantic Cryptography APIscybersec-prod.s3.amazonaws.com/secdev/wp-content/... · 4 Tips for Better Crypto Code 1. Don’t expect too much from simplified APIs and secure defaults

Regulator Pattern - Models

T. Dumitraș :: Toward Semantic Cryptography APIs 29

Application Regulator External Source

alt [At Regular Intervals] Check for Update

Receive Update Pushes Update

alt [When required or when update not received]

Request Update

App. Operation

Receive Update App. Response

Page 30: Toward Semantic Cryptography APIscybersec-prod.s3.amazonaws.com/secdev/wp-content/... · 4 Tips for Better Crypto Code 1. Don’t expect too much from simplified APIs and secure defaults

Selective Pull Model

T. Dumitraș :: Toward Semantic Cryptography APIs 30

App-Regulator Application Server Server-regulator External Source

alt [At Regular Intervals] Request Certificate

Stapled Response

Signed time stamp

Initiate Connection

Signed timestamp

alt [Signed timestamp not received]

Certificate Certificate validation

Valid/Invalid Certificate

Pull validity

Finalize Connection