Slide 1

Slide 1 text

Crypto Wallets Security for developers Julia Potapenko

Slide 2

Slide 2 text

Security Software Engineer Julia Potapenko @julepka We help companies to protect their sensitive and valuable data. OWASP Zhytomyr Leader. Contributor to OWASP security standards and guides. Women Who Code Kyiv Director

Slide 3

Slide 3 text

OWASP Open Web Application Security Project A nonpro f it foundation that works to improve the security of software OWASP Top 10 OWASP ASVS OWASP WSTG OWASP MASVS/MSTG https://owasp.org/www-project-mobile-security-testing-guide/ https://owasp.org/www-project-application-security-veri f ication-standard/ https://owasp.org/www-project-web-security-testing-guide/ https://owasp.org/www-project-top-ten/

Slide 4

Slide 4 text

Today we will talks about #cryptocurrency_wallets #sensitive_assets #authentication #local_storage #platform #cryptography #dependencies_management

Slide 5

Slide 5 text

How does it work? Your account = your seed / private key Loosing seed / private key = loosing the account Wallet gives access to several accounts The main challenge is to secure seed / private keys

Slide 6

Slide 6 text

Cryptocurrency wallet types Custodial third-party storage Non-custodial user-controled

Slide 7

Slide 7 text

Cryptocurrency wallet types Custodial third-party storage Non-custodial user-controled Hot online Cold of f line

Slide 8

Slide 8 text

https://www.wired.com/story/hack-binance-cryptocurrency-exchange/ Why should devs care?

Slide 9

Slide 9 text

https://www.wired.com/story/hack-binance-cryptocurrency-exchange/ https://www.bbc.com/news/technology-59549606 Why should devs care?

Slide 10

Slide 10 text

https://www.theverge.com/2022/1/24/22898712/crypto- hardware-wallet-hacking-lost-bitcoin-ethereum-nft https://www.wired.com/story/hack-binance-cryptocurrency-exchange/ https://www.bbc.com/news/technology-59549606 Why should devs care?

Slide 11

Slide 11 text

https://www.theverge.com/2022/1/24/22898712/crypto- hardware-wallet-hacking-lost-bitcoin-ethereum-nft https://www.wired.com/story/hack-binance-cryptocurrency-exchange/ https://www.bbc.com/news/technology-59549606 https://www.theverge.com/2021/11/4/22763015/cryptocurrency- fake-wallet-phishing-scam-google-ads-phantom-metamask Why should devs care?

Slide 12

Slide 12 text

https://www.theverge.com/2022/1/24/22898712/crypto- hardware-wallet-hacking-lost-bitcoin-ethereum-nft https://www.wired.com/story/hack-binance-cryptocurrency-exchange/ https://www.bbc.com/news/technology-59549606 https://www.theverge.com/2021/11/4/22763015/cryptocurrency- fake-wallet-phishing-scam-google-ads-phantom-metamask Why should devs care? It is not about blockchain security. It is about application security and user education

Slide 13

Slide 13 text

Cryptocurrency wallet types Custodial third-party storage Non-custodial user-controled Hot online Cold of f line

Slide 14

Slide 14 text

Coinbase wallet example

Slide 15

Slide 15 text

Similar to banking apps, cryptocurrency wallets operate user funds, meaning security baseline should be nearly the same.

Slide 16

Slide 16 text

Similar to banking apps, cryptocurrency wallets operate user funds, meaning security baseline should be nearly the same. Threat vectors considerations • Authentication • Local storage • Platform trust • Cryptography • Communication • User education • Supply chain

Slide 17

Slide 17 text

User Authentication LOCAL VS REMOTE If the app provides users access to a remote service, some form of authentication, such as username/password authentication, is performed at the remote endpoint. No sensitive data should be stored locally on the mobile device. Instead, data should be retrieved from a remote endpoint when needed and only be kept in memory. If sensitive data is still required to be stored locally, it should be encrypted using a key derived from hardware backed storage which requires authentication. – OWASP MASVS 4.1, 2.11, 2.12

Slide 18

Slide 18 text

User Authentication LOCAL VS REMOTE If the app provides users access to a remote service, some form of authentication, such as username/password authentication, is performed at the remote endpoint. No sensitive data should be stored locally on the mobile device. Instead, data should be retrieved from a remote endpoint when needed and only be kept in memory. If sensitive data is still required to be stored locally, it should be encrypted using a key derived from hardware backed storage which requires authentication. – OWASP MASVS 4.1, 2.11, 2.12 But what about deanonymisation? Non-custodial wallets are usually fat clients

Slide 19

Slide 19 text

Password policy Password rotation when leaked Defences against brute-force attacks Step-up authentication Biometry veri f ication User Authentication

Slide 20

Slide 20 text

Know your platform What kind of storage should be used to deliver the best security guarantees?

Slide 21

Slide 21 text

Know your platform What kind of storage should be used to deliver the best security guarantees? Is it a f ile? Can you steal it? Can other apps access it? What about integrity? And Encryption?

Slide 22

Slide 22 text

Know your platform What kind of storage should be used to deliver the best security guarantees? Is it a f ile? Can you steal it? Can other apps access it? What about integrity? And Encryption? It is a developer’s responsibility to know how the storage works on the platform you use.

Slide 23

Slide 23 text

000003.log is a storage f ile of web-extension. You can copy it from one browser and paste into another. Know your platform

Slide 24

Slide 24 text

Objection tool that allows to access Keychain of the device, no jailbreak required Know your platform

Slide 25

Slide 25 text

Cryptography How to encrypt the data with a password?

Slide 26

Slide 26 text

Cryptography How to encrypt the data with a password? You decided to pick AES. You need a key length of 256 bits but the password is shorter. You use a hash function SHA256.

Slide 27

Slide 27 text

Cryptography How to encrypt the data with a password? You decided to pick AES. You need a key length of 256 bits but the password is shorter. You use a hash function SHA256. KDF (Key Derivation Function)

Slide 28

Slide 28 text

Cryptography How to encrypt the data with a password? You decided to pick AES. You need a key length of 256 bits but the password is shorter. You use a hash function SHA256. KDF (Key Derivation Function) Your pick PBKDF2. You need to specify number of rounds for it. Similar to some example in the Internet you pick 2 000.

Slide 29

Slide 29 text

Cryptography How to encrypt the data with a password? You decided to pick AES. You need a key length of 256 bits but the password is shorter. You use a hash function SHA256. KDF (Key Derivation Function) Your pick PBKDF2. You need to specify number of rounds for it. Similar to some example in the Internet you pick 2 000. 310 000

Slide 30

Slide 30 text

Cryptography How to encrypt the data with a password? You decided to pick AES. You need a key length of 256 bits but the password is shorter. You use a hash function SHA256. KDF (Key Derivation Function) Your pick PBKDF2. You need to specify number of rounds for it. Similar to some example in the Internet you pick 2 000. 310 000 CBC or GCM mode? Random IV? … ? ? ?

Slide 31

Slide 31 text

Cryptography How to encrypt the data with a password? You decided to pick AES. You need a key length of 256 bits but the password is shorter. You use a hash function SHA256. KDF (Key Derivation Function) Your pick PBKDF2. You need to specify number of rounds for it. Similar to some example in the Internet you pick 2 000. 310 000 CBC or GCM mode? Random IV? … ? ? ? Don’t roll your own crypto Use Themis https://github.com/cossacklabs/themis Use libsodium

Slide 32

Slide 32 text

Cryptography Comes from mvayngrib/react-native-crypto library… that uses react-native-randombytes library… that uses Stanford Javascript Crypto Library (SJCL) for synchronous random values generation. React Native mobile app example

Slide 33

Slide 33 text

Cryptography Comes from mvayngrib/react-native-crypto library… that uses react-native-randombytes library… that uses Stanford Javascript Crypto Library (SJCL) for synchronous random values generation. SJCL random values generator relies on mouse movements and keyboard listeners. React Native mobile app example

Slide 34

Slide 34 text

Supply chain

Slide 35

Slide 35 text

Supply chain

Slide 36

Slide 36 text

Supply chain

Slide 37

Slide 37 text

Supply chain

Slide 38

Slide 38 text

Supply chain

Slide 39

Slide 39 text

How to identify a good library Looks alive Built for required platform Easy to use, hard to misuse Covered with tests Documentation Secure Performance Licence

Slide 40

Slide 40 text

https://snyk.io/advisor/npm-package/ react-native-sensitive-info How to identify a good library

Slide 41

Slide 41 text

Useful tools Automate and add to PRs SonarQube Snyk Dependabot

Slide 42

Slide 42 text

Useful tools Automate and add to PRs SonarQube Snyk Dependabot SAST (Static Application Security Testing): https://owasp.org/www-community/ Source_Code_Analysis_Tools DAST (Dynamic Application Security Testing): https://owasp.org/www-community/ Vulnerability_Scanning_Tools

Slide 43

Slide 43 text

User is a single point of failure Non-custodial wallets security is the user responsibility.

Slide 44

Slide 44 text

Useful links [Article] Crypto wallets security as seen by security engineers: https://www.cossacklabs.com/blog/crypto-wallets-security/ [Article] Security of React Native libraries: the bad, the worse and the ugly: https://www.cossacklabs.com/blog/react-native-libraries-security/ [Article] React Native security: things to keep in mind: https://www.cossacklabs.com/blog/react-native-app-security/ [Slides] Why can’t developers make it secure: https://speakerdeck.com/julep/why-cant-developers-make-it-secure

Slide 45

Slide 45 text

Thank you! Follow me on Twitter @julepka