cryptography programming on android jinsheng xu associate professor north carolina a&t state...

14
CRYPTOGRAPHY PROGRAMMING ON ANDROID Jinsheng Xu Associate Professor North Carolina A&T State University

Upload: preston-mclaughlin

Post on 24-Dec-2015

212 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: CRYPTOGRAPHY PROGRAMMING ON ANDROID Jinsheng Xu Associate Professor North Carolina A&T State University

CRYPTOGRAPHY PROGRAMMING ON ANDROIDJinsheng Xu

Associate Professor

North Carolina A&T State University

Page 2: CRYPTOGRAPHY PROGRAMMING ON ANDROID Jinsheng Xu Associate Professor North Carolina A&T State University

Why Cryptography Programming?• Mobile devices store tremendous amount of personal and

financial data• Mobile apps access the data over the Internet• Mobile devices are easier to get lost or stolen• Websites vs. Mobile apps

• E.g. On desktop use amazon.com (website) to shop, on mobile devices use Amazon app to shop

Page 3: CRYPTOGRAPHY PROGRAMMING ON ANDROID Jinsheng Xu Associate Professor North Carolina A&T State University

Android’s Storage Options• Internal Storage vs. External Storage

• Internal storage is only accessible by the apps• Not safe if device is rooted.• Bugs

• External storage (SD card) is world-readable

• Full Disk Encryption (FDE)• Provide protection when device is lost or rooted• Has performance issues and not turned on by default

• Use encryption for sensitive data!

Page 4: CRYPTOGRAPHY PROGRAMMING ON ANDROID Jinsheng Xu Associate Professor North Carolina A&T State University

Android’s Crypto Library• Android’s SDK includes JCE (Java Cryptography

Extension)• Symmetric Key, Public Key Ciphers• PBE (Password Based Encryption)• Hash Functions• MAC and Digital Signatures• Random Number Generation

• Android’s SDK includes additional Java library that supports• SSL• X.509 certificate

Page 5: CRYPTOGRAPHY PROGRAMMING ON ANDROID Jinsheng Xu Associate Professor North Carolina A&T State University

Common Mistakes in Cipher Programming - PBE

• What is PBE?• Password Based Encryption• Use password as the key for symmetric key ciphers

• Problems with PBE• Passwords are usually not strong

• Not random enough

• They are not long enough • Needs padding

• Other problems• Using constant IV• Using ECB mode instead of stronger CBC mode• Storing password in the source code

Page 6: CRYPTOGRAPHY PROGRAMMING ON ANDROID Jinsheng Xu Associate Professor North Carolina A&T State University

An example of secure implementation of PBE

• Use password based key derivation functions (PBKDF)• Use password and salt as input

• Salt to protection against rainbow table

• Hash function or MAC to output encryption key• Run above function 1000+ times

• Make password cracking very very slow

• Weak passwords are still vulnerable

• Use strong ciphers• Use random IV• Use strong mode

• CBC

Page 7: CRYPTOGRAPHY PROGRAMMING ON ANDROID Jinsheng Xu Associate Professor North Carolina A&T State University

Common Mistakes in Cipher Programming - SSL

• What is SSL (Secure Socket Layer)?• Secure transport layer communication between client-server.

Based on public key cipher. Server sends digital certificate to client for authentication and key exchange.

• MITM (Man-In-The-Middle) attacks are the biggest threat to SSL• More vulnerable on public wi-fi or public Ethernet.• MITM intercepts digital certificates and replaces with another one.• If client fails to detect this fake certificate, attacker can obtain all

traffic.

Page 8: CRYPTOGRAPHY PROGRAMMING ON ANDROID Jinsheng Xu Associate Professor North Carolina A&T State University

Common Mistakes in Cipher Programming - SSL

• Must authenticate digital certificates• Web Browsers authenticate the certificate

• Check if it is signed by a trusted certificate authority (CA)• Check if the subject of the certificate is the same as the hostname• Check if it has expired

• Mobile apps have to verify the digital certificate• Some mobile apps simply skip verification

Page 9: CRYPTOGRAPHY PROGRAMMING ON ANDROID Jinsheng Xu Associate Professor North Carolina A&T State University

Common Mistakes in Cipher Programming - SSL

• Two ways Android use SSL• HttpsURLConnection

• Applicable to web traffic• Digital certificate verification is done by the library. Also does hostname

verification• Good for certificates signed by trusted CAs

• SSLSocket• Applicable to non-web or web traffic• Verification is not done by this library

Page 10: CRYPTOGRAPHY PROGRAMMING ON ANDROID Jinsheng Xu Associate Professor North Carolina A&T State University

Self-Signed Digital Certificates• A lot of mobile apps use self-signed digital certificates

• Digital certificate signed by trusted CA are expensive• Easy to create using OpenSSL• Free• Not a big problem for mobile apps compared to websites that use

self-signed certificates• Why?

• Studies show that• A lot of apps on Google Play store do not verify certificates• Bad verification that simply accepts all certificates

• Self-signed digital certificate can be secure if programmed correctly

Page 11: CRYPTOGRAPHY PROGRAMMING ON ANDROID Jinsheng Xu Associate Professor North Carolina A&T State University

An example of secure implementation of verification• Let HttpsURLConnection to trust the self-signed CA• Steps: (from Android)

• Load CA’s digital certificate into the app• Create a KeyStore that contains the self-signed CA• Create a TrustManager and initialize it with KeyStore• Create SSLContext that uses TrustManager • Let HttpsURLConnection to use SSLContext

• https://developer.android.com/training/articles/security-ssl.html

Page 12: CRYPTOGRAPHY PROGRAMMING ON ANDROID Jinsheng Xu Associate Professor North Carolina A&T State University

Hostname Verification• If the hostname of a URL is different from the the subject

name in the digital certificate, hostname verification will fail

• Mobile apps needs to override HostnameVerifier to accept the mismatching certificate

Page 13: CRYPTOGRAPHY PROGRAMMING ON ANDROID Jinsheng Xu Associate Professor North Carolina A&T State University

SecureAddressBook: Hands-on Lab• Based on Derek Bana’s Youtube tutorial• Changes made to the original program

• Address book is saved to a Internet server instead of local SQLite database• Address book is accessed with web service API calls• Server accepts both clear text requests and SSL requests• Server’s Digital Certificate is provided

• Login activity is added• Username and password are sent to server for authentication• Has option to ‘save password’• Password is saved in SQLite database in clear text

Page 14: CRYPTOGRAPHY PROGRAMMING ON ANDROID Jinsheng Xu Associate Professor North Carolina A&T State University

SecureAddressBook: Hands-on Lab• Goals

• Secure the client-server communication with SSL• Encrypt the passwords before saving them to the SQLite database