Slide 1

Slide 1 text

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

Slide 2

Slide 2 text

Security talk ahead!

Slide 3

Slide 3 text

#tryswiftnyc @vixentael Why we should think more about security?

Slide 4

Slide 4 text

Users trust Apple platform Users trust us Why we should think more about security? #tryswiftnyc @vixentael

Slide 5

Slide 5 text

Most users trust sensitive data to our app regardless of how well we protect it #tryswiftnyc @vixentael

Slide 6

Slide 6 text

abstract app in a vacuum #tryswiftnyc @vixentael

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

security is set of ultimatum rules security abstract app in a vacuum #tryswiftnyc @vixentael

Slide 9

Slide 9 text

security is set of ultimatum rules abstract app in a vacuum real apps, real ecosystems #tryswiftnyc @vixentael

Slide 10

Slide 10 text

App Flow App Features Code User Problem #tryswiftnyc @vixentael

Slide 11

Slide 11 text

Risk Threat Model Secure Methods Secure Implemen- tations Libs/ Code App Flow App Features Code User Problem #tryswiftnyc @vixentael

Slide 12

Slide 12 text

It is secure #tryswiftnyc @vixentael

Slide 13

Slide 13 text

It is secure against certain threat model and adversary It is secure #tryswiftnyc @vixentael

Slide 14

Slide 14 text

Trust model is whose secrets you trust in a security system #tryswiftnyc @vixentael

Slide 15

Slide 15 text

Everything is broken Trust no one, but the user #tryswiftnyc @vixentael

Slide 16

Slide 16 text

Now let’s apply this to the real app #tryswiftnyc @vixentael

Slide 17

Slide 17 text

No content

Slide 18

Slide 18 text

secret data paranoia pa55w0rd trust What user hero has? #tryswiftnyc @vixentael

Slide 19

Slide 19 text

for saving your important docs during trips Let’s make an app!

Slide 20

Slide 20 text

Architecture and flow user app network server storage #tryswiftnyc @vixentael

Slide 21

Slide 21 text

T2 T3 passive MitM active MitM T1/T4 data loss/ tampering Threats we can handle #tryswiftnyc @vixentael

Slide 22

Slide 22 text

More complicated.. T2 T3 passive MitM active MitM T1/T4 data loss/ tampering T5 verbal key leak T6 phishing / social engineering T7 rubber-hose cryptanalysis T8 satellite imaging of sensitive input T9 EM emissions T10 sandbox escaping T11 misconfiguration T12 random generator abuse T13 random generator abuse T14 EM 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 #tryswiftnyc @vixentael

Slide 23

Slide 23 text

Back to threats we can handle T2 T3 passive MitM active MitM T1/T4 data loss/ tampering #tryswiftnyc @vixentael

Slide 24

Slide 24 text

Threats: T1/T4 attacker steals stored data or tampers it #tryswiftnyc @vixentael

Slide 25

Slide 25 text

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. #tryswiftnyc @vixentael

Slide 26

Slide 26 text

Threats: T2 attacker captures network traffic (passive MitM) #tryswiftnyc @vixentael

Slide 27

Slide 27 text

Threats: T2 attacker 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. #tryswiftnyc @vixentael

Slide 28

Slide 28 text

Threats: T3 attacker redirects traffic and pretends to be remote party (active MitM) #tryswiftnyc @vixentael

Slide 29

Slide 29 text

Threats: T3 attacker 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. #tryswiftnyc @vixentael

Slide 30

Slide 30 text

Protection methods T2 T3 passive MitM active MitM T1/T4 data loss/ tampering Secret Key Crypto PKC + ephem. keys PKC + cert. pinning #tryswiftnyc @vixentael

Slide 31

Slide 31 text

Public Key Crypto Perfect Forward Secrecy Secret Key Crypto Authenticated Encryption Certificate Pinning Trust model Trust the user only #tryswiftnyc @vixentael

Slide 32

Slide 32 text

Relationship model plain data symmetric encryption PKC + eph. keys symmetric encryption PKC + eph. keys ZKP ZKP #tryswiftnyc @vixentael

Slide 33

Slide 33 text

…what if trapdoor function fails? …what if key exchange is flawed? …what if we suspect that server is fraudulent? add more paranoia! #tryswiftnyc @vixentael

Slide 34

Slide 34 text

…what if trapdoor function fails? …what if key exchange is flawed? add more paranoia! …what if we suspect that server is fraudulent? Zero Knowledge Proof for the rescue! #tryswiftnyc @vixentael

Slide 35

Slide 35 text

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 #tryswiftnyc @vixentael

Slide 36

Slide 36 text

So, data model: Secret key (SK) = KDF(user password) #tryswiftnyc @vixentael

Slide 37

Slide 37 text

Secret key (SK) = KDF(user password) Sensitive Data (SD) — passport photo Metadata (M1) — timestamp+CRC of photo Metadata (M2) — name of photo (user inputs) So, data model: #tryswiftnyc @vixentael

Slide 38

Slide 38 text

Secret key (SK) = KDF(user password) Sensitive Data (SD) — passport photo Metadata (M1) — timestamp+CRC of photo Metadata (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. So, data model: #tryswiftnyc @vixentael

Slide 39

Slide 39 text

Pwd Key + Data model SD M1 M2 MKP SKP SK #tryswiftnyc @vixentael

Slide 40

Slide 40 text

Pwd MKP SKP SK symmetric encryption PKC + eph. keys PKC + eph. keys Rand KDF() Rand User-centric trust #tryswiftnyc @vixentael

Slide 41

Slide 41 text

App Flows

Slide 42

Slide 42 text

Crypto primitives* Symmetric crypto SCell Asymmetric crypto based on ephemeral keys SSession SComparator ZKP implementation *based on Themis crypto lib https://github.com/cossacklabs/themis #tryswiftnyc @vixentael

Slide 43

Slide 43 text

2. Store EncData, M1, M2 in Local Store 3. Drop SD, SK from memory prepare data 1. Encrypt photo EncData = SCell_wrap(SD, SK, Context=M2) Send photo to server #tryswiftnyc @vixentael

Slide 44

Slide 44 text

2. Store EncData, M1, M2 in Local Store 3. Drop SD, SK from memory prepare data transfer data 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 #tryswiftnyc @vixentael

Slide 45

Slide 45 text

Send photo to server 1. 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

Slide 46

Slide 46 text

Send photo to server 1. 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

Slide 47

Slide 47 text

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 Read photo from server #tryswiftnyc @vixentael

Slide 48

Slide 48 text

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 Read photo from server #tryswiftnyc @vixentael

Slide 49

Slide 49 text

Read photo from server 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) 4. Request password from user 5. Decrypt data: SD = SCell_unwrap(EncData, SK, Context=M2) initialize connection transfer data decrypt data

Slide 50

Slide 50 text

Read photo from server 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) 4. Request password from user 5. Decrypt data: SD = SCell_unwrap(EncData, SK, Context=M2) initialize connection transfer data decrypt data

Slide 51

Slide 51 text

Make it tough even more

Slide 52

Slide 52 text

Apple enforces good security practices iOS 10 use 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 drop TLS < 1.2 #tryswiftnyc @vixentael

Slide 53

Slide 53 text

https://www.blackhat.com/docs/us-16/materials/us-16-Krstic.pdf Apple enforces good security practices

Slide 54

Slide 54 text

̣ 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 Key points! #tryswiftnyc @vixentael

Slide 55

Slide 55 text

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 #tryswiftnyc @vixentael

Slide 56

Slide 56 text

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 #tryswiftnyc @vixentael

Slide 57

Slide 57 text

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 https://info.lookout.com/rs/051-ESQ-475/images/lookout-pegasus-technical-analysis.pdf Technical Analysis of Pegasus Spyware #tryswiftnyc @vixentael https://medium.com/@9gunpi/side-effects-of-pegasus-malware-32c9a112ec1c Side effect of Pegasus malware

Slide 58

Slide 58 text

The last slide Need help? Talk to me :) @vixentael Lead Developer at stanfy.com Core Contributor at themis/ cossacklabs.com