building user-centric security model in ios apps

79
Building user-centric security model in iOS apps #eatdog @vixentael

Upload: eatdog

Post on 16-Apr-2017

479 views

Category:

Software


1 download

TRANSCRIPT

Page 1: Building user-centric security model in iOS apps

Building user-centric security model

in iOS apps

#eatdog @vixentael

Page 2: Building user-centric security model in iOS apps

#eatdog @vixentael

Why we should think more about security?

Page 3: Building user-centric security model in iOS apps

Users trust Apple platform Users trust us

Why we should think more about security?

#eatdog @vixentael

Page 4: Building user-centric security model in iOS apps

Security talks focus on details,

instead of telling the base principles

#eatdog @vixentael

Page 5: Building user-centric security model in iOS apps

#eatdog @vixentael

abstract app in a vacuum

Page 6: Building user-centric security model in iOS apps

#eatdog @vixentael

security is set of ultimatum rules

security

abstract app in a vacuum

Page 7: Building user-centric security model in iOS apps

#eatdog @vixentael

security is set of ultimatum rules

abstract app in a vacuum

real apps,

real

ecosystems

Page 8: Building user-centric security model in iOS apps

#eatdog @vixentael

App FlowApp

FeaturesCode

User Problem

Page 9: Building user-centric security model in iOS apps

Risk Threat Model

Secure Methods

Secure Implemen-

tations

Libs/ Code

App FlowApp

FeaturesCode

User Problem

#eatdog @vixentael

Page 10: Building user-centric security model in iOS apps

It is secure

#eatdog @vixentael

Page 11: Building user-centric security model in iOS apps

It is secure against certain threat model and adversary

It is secure

#eatdog @vixentael

Page 12: Building user-centric security model in iOS apps

https://twitter.com/mubix/status/745403991475904513#eatdog @vixentael

Page 13: Building user-centric security model in iOS apps

Risk Model & Threat Model create demands

for security

#eatdog @vixentael

Page 14: Building user-centric security model in iOS apps

Real world risks

Data leak/ data tampering

Reputation risks

Legal responsibility

Financial damage

#eatdog @vixentael

Page 15: Building user-centric security model in iOS apps

Risk impactData is used/sold by someone

Data is tampered and you’re operating on adversary’s plan

Identity/auth is used elsewhere

DL DT

data leakage

data tampering

identity theft

Page 16: Building user-centric security model in iOS apps

Risk preventiondata leakage

data tampering

identity theft

confidentiality (secrecy)

integrity

authentication#eatdog @vixentael

Page 17: Building user-centric security model in iOS apps

- Encryption w/ secret or PKC - Limit access

- Signed encryption - Protected transport with trust

and integrity

- Authenticated encryption - Action authentication

Risk prevention (for us)confidentiality

(secrecy)

integrity

authentication#eatdog @vixentael

Page 18: Building user-centric security model in iOS apps

Encryption is letting only those who know the secret to access the data,

no matter how they alter the code or the system

(read Kerckhoffs's desideratum)

#eatdog @vixentael

Page 19: Building user-centric security model in iOS apps

Trust model is whose secrets you trust

in a security system

#eatdog @vixentael

Page 20: Building user-centric security model in iOS apps

Everything is broken

#eatdog @vixentael

Trust no one, but the user

Page 21: Building user-centric security model in iOS apps

Risks

Trust model

Threat model

Methods and instruments

#eatdog @vixentael

Page 22: Building user-centric security model in iOS apps

Now let’s apply this to the real app

#eatdog @vixentael

Page 23: Building user-centric security model in iOS apps

secret dataparanoia

pa55w0rd

#eatdog @vixentael

trust

What user has?

Page 24: Building user-centric security model in iOS apps

for saving your important docs during trips

Let’s make an app!

Page 25: Building user-centric security model in iOS apps

Take pictures of important documents

App functionality

Store them on serverLets user see them

#eatdog @vixentael

Page 26: Building user-centric security model in iOS apps

Architecture and flow

#eatdog @vixentael

user app network server storage

Page 27: Building user-centric security model in iOS apps

#eatdog @vixentael

T2 T3passive MitM active MitM

T1/T4 data loss/tampering

Threats we can handle

Page 28: Building user-centric security model in iOS apps

More complicated..

#eatdog @vixentael

T2 T3passive MitM active MitM

T1/T4 data loss/tampering

T5verbal key leak

T6phishing / social

engineering

T7rubber-hose

cryptanalysis

T8

satellite imaging

of sensitive input

T9 EM emissions

T10sandbox escaping

T11misconfiguration

T12random generator

abuseT13

random generator abuse

T14EM emissions and

physical side channel

T15

physical access

T16

malicious dependency

T17 misconfigured access

T18 unattended backups

T19 storing keys with data

T20 weak cipher

random generator abuse

T21

Page 29: Building user-centric security model in iOS apps

#eatdog @vixentael

Back to threats we can handle

T2 T3passive MitM active MitM

T1/T4 data loss/tampering

Page 30: Building user-centric security model in iOS apps

#eatdog @vixentael

Threats: T1/T4attacker steals stored data or tampers it

Page 31: Building user-centric security model in iOS apps

attacker steals stored data or tampers it

Threats: T1/T4

Secret Key Crypto

Protection

Symmetric crypto for storing data. If user has no secret, he can’t read or change

data.#eatdog @vixentael

Page 32: Building user-centric security model in iOS apps

#eatdog @vixentael

Threats: T2attacker captures network traffic (passive MitM)

Page 33: Building user-centric security model in iOS apps

Threats: T2attacker captures network traffic (passive MitM)

Public Key Cryptography, ephemeral keys

Protection

Asymmetric crypto for sending data. Ephemeral keys to avoid decrypting accumulated traffic if

keys are leaked/cracked.#eatdog @vixentael

Page 34: Building user-centric security model in iOS apps

#eatdog @vixentael

Threats: T3attacker redirects traffic and pretends to be remote

party (active MitM)

Page 35: Building user-centric security model in iOS apps

Threats: T3attacker redirects traffic and pretends to be remote

party (active MitM)

Public Key Cryptography, certificate pinning

Protection

Asymmetric crypto for sending data. Check server certificate to make sure it matches

with pinned one.#eatdog @vixentael

Page 36: Building user-centric security model in iOS apps

Protection methods

T2 T3passive MitM active MitM

T1/T4 data loss/tampering

Secret Key

Crypto

PKC + ephem.

keys

PKC + cert.

pinning

#eatdog @vixentael

Page 37: Building user-centric security model in iOS apps

Public Key Crypto

Perfect Forward Secrecy

Secret Key Crypto

Authenticated Encryption

Certificate Pinning

Trust model

Trust the user only#eatdog @vixentael

Page 38: Building user-centric security model in iOS apps

Relationship model

plain data

symmetric encryption

PKC + eph. keys

symmetric encryption

PKC + eph. keys

ZKP ZKP#eatdog @vixentael

Page 39: Building user-centric security model in iOS apps

…what if trapdoor function fails?…what if key exchange is flawed?…what if we suspect that server is fraudulent?

#eatdog @vixentael

add more paranoia!

Page 40: Building user-centric security model in iOS apps

…what if trapdoor function fails?…what if key exchange is flawed?

add more paranoia!

…what if we suspect that server is fraudulent?

Zero Knowledge Prooffor the rescue!

#eatdog @vixentael

Page 41: Building user-centric security model in iOS apps

ZKP is comparing shared secret without transmitting it

does not require the key exchange, does not leak password

https://www.cossacklabs.com/zero-knowledge-protocols-without-magic.html

#eatdog @vixentael

Page 42: Building user-centric security model in iOS apps

So, data model:Secret key (SK) = KDF(user password)

#eatdog @vixentael

Page 43: Building user-centric security model in iOS apps

Secret key (SK) = KDF(user password)

Sensitive Data (SD) — passport photoMetadata (M1) — timestamp+CRC of photoMetadata (M2) — name of photo (user inputs)

#eatdog @vixentael

So, data model:

Page 44: Building user-centric security model in iOS apps

Secret key (SK) = KDF(user password)

Sensitive Data (SD) — passport photoMetadata (M1) — timestamp+CRC of photoMetadata (M2) — name of photo (user inputs)

Mobile Key Pair (MKP) — private+public keys gen. inside app.

Server Key Pair (SKP) — private+public keys gen. on server. App pins Server Public Key.

#eatdog @vixentael

So, data model:

Page 45: Building user-centric security model in iOS apps

Pwd

Key + Data model

#eatdog @vixentael

SDM1

M2 MKP SKP

SK

Page 46: Building user-centric security model in iOS apps

Pwd

MKP SKP

SK symmetric encryption

PKC + eph. keys

PKC + eph. keysRand

KDF()

Rand

User-centric trust

#eatdog @vixentael

Page 47: Building user-centric security model in iOS apps

App Flows

#eatdog @vixentael

Page 48: Building user-centric security model in iOS apps

Crypto primitives*Symmetric crypto SCell

Asymmetric crypto based on ephemeral keys

SSession

SComparator ZKP implementation

#eatdog @vixentael

*based on Themis crypto libhttps://github.com/cossacklabs/themis

Page 49: Building user-centric security model in iOS apps

2. Store EncData, M1, M2 in Local Store 3. Drop SD, SK from memory

prepare data

#eatdog @vixentael

1. Encrypt photo EncData = SCell_wrap(SD, SK, Context=M2)

Send photo to server

Page 50: Building user-centric security model in iOS apps

2. Store EncData, M1, M2 in Local Store 3. Drop SD, SK from memory

prepare data

transfer data

#eatdog @vixentael

4. Connect to Server: Session = SSession(Priv(MKP), Pub(SKP)) 5. Send EncData, M1, M2 via Session

1. Encrypt photo EncData = SCell_wrap(SD, SK, Context=M2)

Send photo to server

Page 51: Building user-centric security model in iOS apps

Send photo to server1. Encrypt photo EncData = SCell_wrap(SD, SK, Context=M2)

6. Receive OK 7. Terminate Session 8. Mark EncData in Local Store as Synced

2. Store EncData, M1, M2 in Local Store 3. Drop SD, SK from memory

4. Connect to Server: Session = SSession(Priv(MKP), Pub(SKP)) 5. Send EncData, M1, M2 via Session

prepare data

transfer data

terminate session

Page 52: Building user-centric security model in iOS apps

Send photo to server1. Encrypt photo EncData = SCell_wrap(SD, SK, Context=M2)

6. Receive OK 7. Terminate Session 8. Mark EncData in Local Store as Synced

2. Store EncData, M1, M2 in Local Store 3. Drop SD, SK from memory

4. Connect to Server: Session = SSession(Priv(MKP), Pub(SKP)) 5. Send EncData, M1, M2 via Session

prepare data

transfer data

terminate session

Page 53: Building user-centric security model in iOS apps

1. Connect to Server: Session = SSession(Priv(MKP), Pub(SKP))2. Request EncData proof via ZKP: 2.1 Send M1 2.2 Request Server to prove he has M2 by performing SComparator(M2)

initialize connection

#eatdog @vixentael

Read photo from server

Page 54: Building user-centric security model in iOS apps

1. Connect to Server: Session = SSession(Priv(MKP), Pub(SKP))

3. Receive EncData

2. Request EncData proof via ZKP: 2.1 Send M1 2.2 Request Server to prove he has M2 by performing SComparator(M2)

initialize connection

transfer data

#eatdog @vixentael

Read photo from server

Page 55: Building user-centric security model in iOS apps

Read photo from server1. Connect to Server: Session = SSession(Priv(MKP), Pub(SKP))

3. Receive EncData

2. Request EncData proof via ZKP: 2.1 Send M1 2.2 Request Server to prove he has M2 by performing SComparator(M2)

4. Request password from user 5. Decrypt data: SD = SCell_unwrap(EncData, SK, Context=M2)

initialize connection

transfer data

decrypt data

Page 56: Building user-centric security model in iOS apps

Read photo from server1. Connect to Server: Session = SSession(Priv(MKP), Pub(SKP))

3. Receive EncData

2. Request EncData proof via ZKP: 2.1 Send M1 2.2 Request Server to prove he has M2 by performing SComparator(M2)

4. Request password from user 5. Decrypt data: SD = SCell_unwrap(EncData, SK, Context=M2)

initialize connection

transfer data

decrypt data

Page 57: Building user-centric security model in iOS apps

Code samples

Page 58: Building user-centric security model in iOS apps

Generate keys

#eatdog @vixentael

// Generating EC keys guard let keyGeneratorEC: TSKeyGen = TSKeyGen(algorithm: .EC) else { print("Error occurred while initializing object keyGeneratorEC”) return }

let privateKeyEC: NSData = keyGeneratorEC.privateKey let publicKeyEC: NSData = keyGeneratorEC.publicKey

https://github.com/cossacklabs/themis/wiki/Swift-Howto

Page 59: Building user-centric security model in iOS apps

Symmetric encryption

#eatdog @vixentael

let masterKeyData: NSData = self.generateMasterKey() guard let cellSeal: TSCellSeal = TSCellSeal(key: masterKeyData) else { print("Error occurred while initializing object cellSeal", #function) return } let message: String = "All your base are belong to us!" let context: String = "For great justice"

var encryptedMessage: NSData = NSData() do { // context is optional parameter and may be ignored encryptedMessage = try cellSeal.wrapData(message.dataUsingEncoding(NSUTF8StringEncoding), context: context.dataUsingEncoding(NSUTF8StringEncoding)) print("encryptedMessages = \(encryptedMessage)") } catch let error as NSError { print("Error occurred while encrypting \(error)", #function) return }

https://github.com/cossacklabs/themis/wiki/Swift-Howto

Page 60: Building user-centric security model in iOS apps

Symmetric decryption

#eatdog @vixentael

let masterKeyData: NSData = self.generateMasterKey() guard let cellSeal: TSCellSeal = TSCellSeal(key: masterKeyData) else { print("Error occurred while initializing object cellSeal", #function) return } let message: String = "All your base are belong to us!" let context: String = "For great justice"

do { let decryptedMessage: NSData = try cellSeal.unwrapData(encryptedMessage, context: context.dataUsingEncoding(NSUTF8StringEncoding)) let resultString: String = String(data: decryptedMessage, encoding: NSUTF8StringEncoding)! print("decryptedMessage = \(resultString)") } catch let error as NSError { print("Error occurred while decrypting \(error)", #function) return }

https://github.com/cossacklabs/themis/wiki/Swift-Howto

Page 61: Building user-centric security model in iOS apps

Initialize Session

#eatdog @vixentael

guard let clientIdData: NSData = kClientId.dataUsingEncoding(NSUTF8StringEncoding), let clientPrivateKey: NSData = NSData(base64EncodedString: kClientPrivateKey, options: .IgnoreUnknownCharacters) else { print("Error occurred during base64 encoding", #function) return }

self.transport = Transport() self.transport?.setupKeys(kServerId, serverPublicKey: kServerPublicKey) self.session = TSSession(userId: clientIdData, privateKey: clientPrivateKey, callbacks: self.transport)

https://github.com/cossacklabs/themis/wiki/Swift-Howto

Page 62: Building user-centric security model in iOS apps

Encrypt/Decrypt Session messages

#eatdog @vixentael

var encryptedMessage: NSData do { guard let wrappedMessage: NSData = try self.session?.wrapData(message.dataUsingEncoding(NSUTF8StringEncoding)) else { print("Error occurred during wrapping message ", #function) return } encryptedMessage = wrappedMessage } catch let error as NSError { print("Error occurred while wrapping message \(error)", #function) completion(data: nil, error: error) return }

//... do { guard let decryptedMessage: NSData = try self.session?.unwrapData(data), let resultString: String = String(data: decryptedMessage, encoding: NSUTF8StringEncoding) else { throw NSError(domain: "com.example", code: -3, userInfo: nil) } completion(data: resultString, error: nil) } catch let error as NSError { print("Error occurred while decrypting message \(error)", #function) completion(data: nil, error: error) return } https://github.com/cossacklabs/themis/wiki/Swift-Howto

Page 63: Building user-centric security model in iOS apps

accumulate encrypted data

accumulate metadata DoS

Possible attacks

#eatdog @vixentael

Page 64: Building user-centric security model in iOS apps

Make it tough even more

Page 65: Building user-centric security model in iOS apps

one password per photo

Enforce app security

user inputs password every time on photo access

#eatdog @vixentael

Page 66: Building user-centric security model in iOS apps

#eatdog @vixentael

Repeated auth

D1

D2

Dn...

Received items

request ZKP(M1i)

select any Di, where Di = (EncData, M1, M2)

prove M2i

transfer Dn+1compare M2i, on success

Synced items

D1

D2

Dn...

Page 67: Building user-centric security model in iOS apps

#eatdog @vixentael

Repeated auth

Use ZKP to prove that Server has M2 from any previous

transfer

Page 68: Building user-centric security model in iOS apps

Best active MitM + hack server:

#eatdog @vixentael

The worst scenario attacks

Attacker seizes SKP from Server and pretends to be normal server by DNS spoofing or routing redirection.

Results:Accumulates useless M1, M2 and lousy EncData.

Page 69: Building user-centric security model in iOS apps

Active MitM without hacking the server:

#eatdog @vixentael

The worst scenario attacks

Attacker does not have SKP.

Results:SecureSession initialization fails. App doesn’t start transfer data to server at all.

Page 70: Building user-centric security model in iOS apps

Denial of Service:

#eatdog @vixentael

The worst scenario attacks

Attacker flood server with requests / tons of data.

Results:Server may be flooded. Monitor all the things!

Page 71: Building user-centric security model in iOS apps

Finalizing…

Page 72: Building user-centric security model in iOS apps

* hardware support (AES)

Crypto is very expensive!!11

https://www.cossacklabs.com/benchmarking-secure-comparator.html

* scripted language and questionable frameworks affect performance as much as running the expensive math, if not more

* endorse crypto everywhere to make it more cheap :)

#eatdog @vixentael

(it is not)

Page 73: Building user-centric security model in iOS apps

Apple enforces good security practices

iOS 10use HTTPS everywhere!

https://developer.apple.com/videos/play/wwdc2016/706/

http://useyourloaf.com/blog/privacy-settings-in-ios-10/

add purpose strings for accessing private data

https://nabla-c0d3.github.io/blog/2016/08/14/ats-enforced-2017/

read more about Apple security care in Additional reading section

#eatdog @vixentael

drop TLS < 1.2

Page 74: Building user-centric security model in iOS apps

https://www.blackhat.com/docs/us-16/materials/us-16-Krstic.pdf

Apple enforces good security practices

Page 75: Building user-centric security model in iOS apps

Security is a system, not a set of methods

You may need to re-read this slides when you will plan your next app

User-centric trust is simple to implement, yet almost impossible to hack

#eatdog @vixentael

Key points!

Page 76: Building user-centric security model in iOS apps

@vixentael

Lead Developer at stanfy.com

iOS contributor at Themis/

cossacklabs.com

The last slide

Page 77: Building user-centric security model in iOS apps

My other security talks

https://medium.com/@vixentael/upgrading-approaches-to-the-secure-mobile-architectures-7a8fcb10d28a#.ffbsjwqx6

Upgrading Approaches to the Secure Mobile Architectures

https://medium.com/stanfy-engineering-practices/data-protection-for-mobile-client-server-architectures-6e6dcabd871a

Data Protection For Mobile Client-Server Architectures

https://speakerdeck.com/vixentael/users-data-security-in-ios-applications

Users' data security in iOS applications

#eatdog @vixentael

Page 78: Building user-centric security model in iOS apps

Additional reading by Apple

https://developer.apple.com/videos/play/wwdc2016/705/

How iOS Security Really Works

https://developer.apple.com/videos/play/wwdc2016/706/

What's New in Security

https://www.blackhat.com/docs/us-16/materials/us-16-Krstic.pdf

Behind the Scenes with iOS Security

https://developer.apple.com/videos/play/wwdc2016/709/

Engineering Privacy for Your Users

#eatdog @vixentael

Page 79: Building user-centric security model in iOS apps

Additional reading by smarties

https://nabla-c0d3.github.io/blog/2016/08/14/ats-enforced-2017/

Getting Ready for ATS Enforcement in 2017

http://useyourloaf.com/blog/privacy-settings-in-ios-10/

Privacy Settings in iOS 10

https://www.cossacklabs.com/zero-knowledge-protocols-without-magic.html

Zero Knowledge Protocols Without Magic

#eatdog @vixentael

https://speakerdeck.com/mbazaliy/a-journey-through-exploit-mitigation-techniques-on-ios

A Journey Through Exploit Mitigation Techniques on iOS