SlideShare una empresa de Scribd logo
1 de 62
Descargar para leer sin conexión
AnDevCon IV


Securing User
  Data with
 SQLCipher
    Copyright © 2012 CommonsWare, LLC
Workshop Overview
●   Who Is At Risk?
●   Offense and Defense
●   SQLCipher Integration
●   SQLCipher: Hands On!
●   Encrypting SharedPreferences & Files
●   Passphrases
●   Encrypted Communications
                      Copyright © 2012 CommonsWare, LLC
Who Is At Risk?
●   The Clumsy
    –   Leaving phones lie around
    –   Some percentage get personal data lifted
●   The Traveler
    –   Spear-fishing attack on a specific business
    –   Corporate espionage or just garden-variety theft


                       Copyright © 2012 CommonsWare, LLC
Who Is At Risk?
●   The Freedom Fighter
    –   Devices used for communication, coordination
    –   Devices confiscated upon arrest
●   The Terrorist
    –   Devices used for communication, coordination
    –   Devices confiscated upon arrest


                      Copyright © 2012 CommonsWare, LLC
Who Is At Risk?
●   The Citizen (of Repressive Regimes)
    –   Arrests ranging from freedom of expression
        (protest rallies) to “just because” (race, religion,
        etc.)
●   The User
    –   May fall into any of the above categories
    –   Even for apps not normally thought of as
        requiring such security
                        Copyright © 2012 CommonsWare, LLC
Who Is At Risk?
●   The Developer
    –   Press reports of “plaintext” stuff on internal
        storage
    –   Negative publicity leads to negative reputation




                       Copyright © 2012 CommonsWare, LLC
Offense and Defense
●   Defense: Lock Screen Security
    –   Swipe: um, not really
    –   Face: well, better than nothing
    –   PIN: we're getting somewhere
    –   Password: secure!
         ●   Right?



                      Copyright © 2012 CommonsWare, LLC
Offense and Defense
●   Offense: Exploits
    –   Example: USB Debugging
         ●   Create app that dismisses keyguard
         ●   Run via USB cable and adb shell am
         ●   Net: bypass lock screen regardless of security
             settings
         ●   (according to Google: not a bug)



                           Copyright © 2012 CommonsWare, LLC
Offense and Defense
●   Defense: Internal Storage
    –   Read-write for app, deny-all for everyone else
    –   User has no direct access via USB cable
    –   Net: only way to get at the data is via the app!
         ●   Right?




                       Copyright © 2012 CommonsWare, LLC
Offense and Defense
●   Offense: Rooting
    –   Most devices can be rooted
    –   Can run apps as root, with access to all parts of
        internal storage
    –   Run a file manager, copy off whatever is desired
         ●   Or write an app that bulk-copies entire internal
             storage for later analysis


                           Copyright © 2012 CommonsWare, LLC
Offense and Defense
●   Defense: Full-Disk Encryption
    –   Entire internal storage bulk encrypted
    –   Reboot locks down device, requiring manual
        entry of password
    –   Many root attacks require a reboot
    –   Net: only way to get at data is via encryption
        password!
         ●   Right?
                       Copyright © 2012 CommonsWare, LLC
Offense and Defense
●   Offense: Exploits
    –   Ineffective against many temporary root attacks
    –   Weak full-disk encryption passwords
         ●   Same as lock screen for most devices
         ●   Can be brute-forced
    –   Assumes users know of, apply full-disk
        encryption
         ●   Not offered during initial setup
                           Copyright © 2012 CommonsWare, LLC
Offense and Defense
●   Defense: Cloud
    –   Keep data off the device
    –   Many Web sites and apps have decent defenses
        against brute-forcing attacks
    –   So long as user is willing to enter password every
        time, the data is secure!
         ●   Right?


                       Copyright © 2012 CommonsWare, LLC
Offense and Defense




 xkcd comics reproduced under CC license from Randall Munroe, despite Hat Guy's best efforts.

                      Copyright © 2012 CommonsWare, LLC
General Strategy
●   Use Base Defenses
    –   Lockscreen
    –   Internal Storage
    –   Full-Disk Encryption




                      Copyright © 2012 CommonsWare, LLC
General Strategy
●   Per-App Crypto
    –   More flexible authentication models
         ●   Help to mitigate “always entering password”
             problem
    –   Containers with better brute-force resistance
    –   Storage Models
         ●   Database
         ●   SharedPreferences
         ●   General files
                             Copyright © 2012 CommonsWare, LLC
Introducing SQLCipher
●   SQLCipher
    –   Modified version of SQLite
    –   AES-256 encryption by default, of all data
    –   Relatively low overhead
    –   Cross-platform
    –   BSD license


                      Copyright © 2012 CommonsWare, LLC
Introducing SQLCipher
●   SQLCipher Security
    –   Customizable encryption algorithm
         ●   Based on OpenSSL libcrypto
    –   Individual pages encrypted, with own
        initialization vector
    –   Message authentication code (MAC) per page, to
        detect tampering
    –   Hashed passphrase (PBKDF2) for key
                   Xkcd comics reproduced under CC license from Randall Munroe. Hat guy is not impressed.

                                     Copyright © 2012 CommonsWare, LLC
Introducing SQLCipher
●   SQLCipher for Android
    –   NDK-compiled binaries
    –   Drop-in replacement classes for Android's
        SQLite classes
         ●   SQLiteDatabase
         ●   SQLiteOpenHelper
         ●   Etc.


                        Copyright © 2012 CommonsWare, LLC
Introducing SQLCipher
●   SQLCipher for Android Limitations
    –   Adds ~3MB to APK size per CPU architecture
    –   x86 binaries not available for public download
        right now
         ●   Must build them yourself, versus downloading ARM
             binaries
         ●   Available for this workshop!



                          Copyright © 2012 CommonsWare, LLC
Introducing SQLCipher
●   SQLCipher and Third Party Code
    –   Typically should work for open source via fork
         ●   Replace their references to SQLite classes the same
             way you would replace your references
         ●   Find way to pass in passphrase
         ●   Either package as separate JAR or blend their source
             into your project as needed
         ●   Examples: ORMLite, SQLiteAssetHelper

                          Copyright © 2012 CommonsWare, LLC
Integrating SQLCipher
●   Step #1: Add to Project
    –   Download ZIP file from:
        https://github.com/sqlcipher/android-database-sqlcipher

    –   Copy ZIP's assets/ into project's assets/
    –   Copy ZIP's libs/ into project's libs/




                         Copyright © 2012 CommonsWare, LLC
Integrating SQLCipher
●   Step #2: Replace Import Statements
    –   Eclipse
         ●   Delete all android.database.* and
             android.database.sqlite.* imports
         ●   Use Ctrl-Shift-O and choose the net.sqlcipher
             equivalents




                         Copyright © 2012 CommonsWare, LLC
Integrating SQLCipher
●   Step #2: Replace Import Statements
    –   Outside of Eclipse
         ●   Replace all occurrences of android.database with
             net.sqlcipher, revert back as needed
         ●   Replace all occurrences of
             android.database.sqlite with
             net.sqlcipher.database



                         Copyright © 2012 CommonsWare, LLC
Integrating SQLCipher
●   Step #3: Supply Passphrases
    –   SQLiteDatabase openOrCreateDatabase(),
        etc.
    –   SQLiteOpenHelper getReadableDatabase()
        and getWritableDatabase()
    –   Collect passphrase from user via your own UI



                      Copyright © 2012 CommonsWare, LLC
Integrating SQLCipher
●   Step #4: Testing
    –   Tests should work when starting with a clean
        install
         ●   No existing unencrypted database
●   Step #5: Beer!
    –   Hooray, beer!



                         Copyright © 2012 CommonsWare, LLC
Integrating SQLCipher
●   Upgrading to Encryption
    –   Open unencrypted original
    –   Create and ATTACH new encrypted database
    –   sqlcipher_export()
    –   Save schema version from old database
    –   DETACH and close databases
    –   Open encrypted database and set schema
        version
                     Copyright © 2012 CommonsWare, LLC
SQLCipher: Hands On!
●   Option #1: Tutorial
    –   Materials on USB thumb drive
    –   Step-by-step instructions (PDF)
    –   Live walkthrough of all steps
         ●   Designed to supplement instructions
    –   Goal: add SQLCipher to an existing Android app,
        including handling the database upgrade

                          Copyright © 2012 CommonsWare, LLC
SQLCipher: Hands On!
●   Option #2: Upgrade Your Own App
    –   Use instructions, walkthrough as guide for applying
        similar changes to your own code
         ●   Warning: tutorial probably smaller than your app!
●   Support
    –   Ask questions of presenter, who will be up front or
        wandering around aimlessly between walkthrough
        sections


                           Copyright © 2012 CommonsWare, LLC
SQLCipher: Hands On!
●   Option #3: Return at 11:25am for more
    exciting slides!
    –   ...though we will all miss you...




                       Copyright © 2012 CommonsWare, LLC
SQLCipher: Hands On!
●   Step #1: Getting Your Starting Point
●   Step #2: Adding SQLCipher for Android
●   Step #3: Adding a New Launcher Activity
●   Step #4: Collect Passphrase For New Encryption
●   Step #5: Create or Encrypt the Database
●   Step #6: Collect Passphrase For Decryption


                     Copyright © 2012 CommonsWare, LLC
SQLCipher: Hands On!
●   Step #1: Getting Your Starting Point
●   Step #2: Adding SQLCipher for Android
●   Step #3: Adding a New Launcher Activity
●   Step #4: Collect Passphrase For New Encryption
●   Step #5: Create or Encrypt the Database
●   Step #6: Collect Passphrase For Decryption


                    Copyright © 2012 CommonsWare, LLC
SQLCipher: Hands On!
●   Step #1: Getting Your Starting Point
●   Step #2: Adding SQLCipher for Android
●   Step #3: Adding a New Launcher Activity
●   Step #4: Collect Passphrase For New Encryption
●   Step #5: Create or Encrypt the Database
●   Step #6: Collect Passphrase For Decryption


                     Copyright © 2012 CommonsWare, LLC
SQLCipher: Hands On!
●   Step #1: Getting Your Starting Point
●   Step #2: Adding SQLCipher for Android
●   Step #3: Adding a New Launcher Activity
●   Step #4: Collect Passphrase For New Encryption
●   Step #5: Create or Encrypt the Database
●   Step #6: Collect Passphrase For Decryption


                     Copyright © 2012 CommonsWare, LLC
SQLCipher: Hands On!
●   Step #1: Getting Your Starting Point
●   Step #2: Adding SQLCipher for Android
●   Step #3: Adding a New Launcher Activity
●   Step #4: Collect Passphrase For New Encryption
●   Step #5: Create or Encrypt the Database
●   Step #6: Collect Passphrase For Decryption


                     Copyright © 2012 CommonsWare, LLC
SQLCipher: Hands On!
●   Step #1: Getting Your Starting Point
●   Step #2: Adding SQLCipher for Android
●   Step #3: Adding a New Launcher Activity
●   Step #4: Collect Passphrase For New Encryption
●   Step #5: Create or Encrypt the Database
●   Step #6: Collect Passphrase For Decryption


                     Copyright © 2012 CommonsWare, LLC
SQLCipher: Hands On!
●   Step #1: Getting Your Starting Point
●   Step #2: Adding SQLCipher for Android
●   Step #3: Adding a New Launcher Activity
●   Step #4: Collect Passphrase For New Encryption
●   Step #5: Create or Encrypt the Database
●   Step #6: Collect Passphrase For Decryption


                     Copyright © 2012 CommonsWare, LLC
Encrypted SharedPreferences
●   How They Are Normally Stored
    –   Unencrypted XML files
    –   Internal storage in shared_prefs/ directory
         ●   Peer to your databases/, files/ directories
         ●   Precise root path may vary, especially on Android 4.2
             with multiple accounts




                          Copyright © 2012 CommonsWare, LLC
Encrypted SharedPreferences
●   Introducing CWSharedPreferences
    –   Strategy-based pluggable storage model
         ●   SQLite
         ●   SQLCipher
         ●   Others as you wish via interfaces
    –   Implements SharedPreferences
         ●   Manual preference-using code requires no changes
             once you have your SharedPreferences object

                          Copyright © 2012 CommonsWare, LLC
Encrypted SharedPreferences
●   Creating a SQLCipherStrategy
    –   Supply name of preferences, passphrase, LoadPolicy
         ●   LoadPolicy.SYNC: loads on main application thread
         ●   LoadPolicy.ASYNC_BLOCK: loads in background thread,
             blocks if you try using them before loaded
         ●   LoadPolicy.ASYNC_EXCEPTION: loads in background
             thread, raises exception if you try using them before
             loaded
●   Test Case Walkthrough

                           Copyright © 2012 CommonsWare, LLC
Encrypted SharedPreferences
●   Limitation: No PreferenceActivity
    –   Hard-wired to use stock SharedPreferences
●   Alternative: Encrypt at GUI Level
    –   Custom Preference classes with encryption,
        decryption logic, also available for use outside of
        preference UI
    –   Requires more manual fussing with encryption
    –   Encrypts values, perhaps not keys
                       Copyright © 2012 CommonsWare, LLC
Encrypted Files
●   Option #1: javax.crypto
    –   Standard solution for Java for years
    –   Plenty of online recipes
    –   Search StackOverflow for Android-specific
        idiosyncrasies




                       Copyright © 2012 CommonsWare, LLC
Encrypted Files
●   Option #2: SpongyCastle
    –   Refactored version of BouncyCastle, to avoid VM
        collisions
         ●   Android's javax.crypto based on BouncyCastle, but
             with somewhat hacked version
    –   Fairly popular, probably less likely to run into
        Android-specific headaches


                          Copyright © 2012 CommonsWare, LLC
Encrypted Files
●   Future Option: IOCipher
    –   Uses SQLCipher as a backing store for virtual
        filesystem
         ●   You work with drop-in replacement File class that
             stores, reads “files” as BLOBs from database
    –   Benefits: less work, benefits of SQLCipher
        container
    –   Pre-alpha

                          Copyright © 2012 CommonsWare, LLC
Passphrases
●   Passphrase Entry Pain
    –   Users do not like typing long passwords
    –   Result = weaker quality
    –   Option: “diceware”
         ●   Choose ~5 words from stock list
         ●   Can offer scrolling lists, auto-complete to help speed
             data entry
         ●   Downside: more annoying for accessibility

                           Copyright © 2012 CommonsWare, LLC
Passphrases




xkcd comics reproduced under CC license from Randall Munroe, even though Hat Guy owns a $5 wrench

                        Copyright © 2012 CommonsWare, LLC
Passphrases




xkcd comics reproduced under CC license from Randall Munroe, but BYO talking horse

                Copyright © 2012 CommonsWare, LLC
Passphrases
●   Multi-Factor Authentication
    –   Passphrase generated in code from user-
        supplied pieces
    –   Organization options
         ●   Simple concatenation
         ●   Concatenation with factor prefix, un-typeable divider
             characters



                          Copyright © 2012 CommonsWare, LLC
Passphrases
●   Multi-Factor Authentication Objectives
    –   Longer passphrase without as much user input
    –   Help defeat casual attacks
         ●   Need all factors to access via your UI
         ●   Otherwise, need to brute-force




                           Copyright © 2012 CommonsWare, LLC
Passphrases




xkcd comics reproduced under CC license from Randall Munroe. Hat Guy is not amused.

                 Copyright © 2012 CommonsWare, LLC
Passphrases
●   Multi-Factor Authentication Sources
    –   NFC tag
    –   QR code
    –   Paired Bluetooth device
    –   Wearable app
    –   Gesture (e.g., pattern lock)
    –   Biometrics (e.g., fingerprint scanner)

                       Copyright © 2012 CommonsWare, LLC
Passphrases
●   Password Managers
    –   Some offer APIs (e.g., OI Password Safe)
    –   Benefit
         ●   Easier: user does not have to remember as many
             passphrases
    –   Downside
         ●   Reliant upon third-party app and its security


                           Copyright © 2012 CommonsWare, LLC
Passphrases
●   Changing SQLCipher Password
    –   PRAGMA rekey = 'new passphrase';
    –   Requires access to database with existing key
    –   Execution time proportional to database size
         ●   Background thread, please!




                          Copyright © 2012 CommonsWare, LLC
Encrypted Communications
●   BackupManager
    –   No control over exactly where this data is sent
         ●   Could be replaced by device manufacturers, carriers
    –   Ideally, all data backed up should be encrypted
        with user passphrase
         ●   Either because that data is always encrypted, or
             encrypt especially for backup/restore
         ●   No sense in using static passphrase, as can be
             reverse-engineered
                          Copyright © 2012 CommonsWare, LLC
Encrypted Communications
●   GCM and C2DM
    –   Data is encrypted during transmission
    –   Data is not encrypted at Google's servers
    –   Options
         ●   Encrypt the message payloads
         ●   Message payloads are pointers to encrypted data
             held elsewhere


                          Copyright © 2012 CommonsWare, LLC
Encrypted Communications
●   SSL: Basics
    –   Use https:// URLs with URL or HttpClient
    –   Use normally
    –   Pray that your certificates are installed
         ●   Self-signed certs
         ●   Unusual certificate authorities
         ●   Varying certificate authorities
    –   http://goo.gl/8anF9
                           Copyright © 2012 CommonsWare, LLC
Encrypted Communications
●   SSL Attack: Hack the CA
    –   Comodo, DigiNotar, etc.
    –   Forged certificates claiming to be Google, Mozilla,
        Microsoft, etc.
    –   “When an attacker obtains a fraudulent certificate, he
        can use it to eavesdrop on the traffic between a user
        and a website even while the user believes that the
        connection is secure.”


                         Copyright © 2012 CommonsWare, LLC
Encrypted Communications
●   SSL Defense #1: Avoid CAs
    –   CAs are needed for general-purpose clients (e.g.,
        Web browsers)
    –   If you control front end (app) and back end (Web
        service), use private SSL certificates that can be
        verified by the app itself
    –   Moxie Marlinspike Implementation
         ●   http://goo.gl/DYTrb
         ●   See Option 1
                            Copyright © 2012 CommonsWare, LLC
Encrypted Communications
●   SSL Defense #2: Pinning
    –   Assumes that you need to use a CA for some
        reason (e.g., Web site + Web service)
    –   Validates issuing CA
         ●   Rather than the certificate itself
         ●   Limits attacks to ones where your CA gets hacked
    –   Moxie Marlinspike Implementation
         ●   http://goo.gl/DYTrb
         ●   See Option 2   Copyright © 2012 CommonsWare, LLC
Encrypted Communications
●   SSL Defense #3: User Validation
    –   Assume that attacks are infrequent
    –   Alert user when you see a different certificate
        than used before
         ●   May indicate a MITM attack
    –   https://github.com/ge0rg/MemorizingTrustManager/wiki
         ●   Implementation of trust store and UI



                           Copyright © 2012 CommonsWare, LLC
Encrypted Communications
●   OnionKit
    –   StrongTrustManager
         ●   Customized set of CAs based on Debian cacerts file
         ●   Full chain verification
         ●   Limited pinning
    –   Proxying through Orbot
         ●   Tor implementation for Android
    –   https://github.com/guardianproject/OnionKit

                           Copyright © 2012 CommonsWare, LLC
Summary
●   Consider Encryption
    –   ...even if you don't think you need it
●   SQLCipher: Easiest Option for Encrypted
    Database
    –   ...if you can live with the APK footprint
●   Think About Encrypting Other Data Stores,
    Means of Collecting Passphrases
●   Q&A                Copyright © 2012 CommonsWare, LLC

Más contenido relacionado

La actualidad más candente

La actualidad más candente (20)

Java I/o streams
Java I/o streamsJava I/o streams
Java I/o streams
 
Java Database Connectivity
Java Database ConnectivityJava Database Connectivity
Java Database Connectivity
 
Introduction to kotlin
Introduction to kotlinIntroduction to kotlin
Introduction to kotlin
 
Kotlin Language powerpoint show file
Kotlin Language powerpoint show fileKotlin Language powerpoint show file
Kotlin Language powerpoint show file
 
C# in depth
C# in depthC# in depth
C# in depth
 
OOP interview questions & answers.
OOP interview questions & answers.OOP interview questions & answers.
OOP interview questions & answers.
 
java.io - streams and files
java.io - streams and filesjava.io - streams and files
java.io - streams and files
 
Object Oriented Programing JAVA presentaion
Object Oriented Programing JAVA presentaionObject Oriented Programing JAVA presentaion
Object Oriented Programing JAVA presentaion
 
java-thread
java-threadjava-thread
java-thread
 
Oop in kotlin
Oop in kotlinOop in kotlin
Oop in kotlin
 
Oops in java
Oops in javaOops in java
Oops in java
 
JSON
JSONJSON
JSON
 
Java And Multithreading
Java And MultithreadingJava And Multithreading
Java And Multithreading
 
Corso Java 1 - BASE
Corso Java 1 - BASECorso Java 1 - BASE
Corso Java 1 - BASE
 
Java Basics
Java BasicsJava Basics
Java Basics
 
Wrapper class
Wrapper classWrapper class
Wrapper class
 
Typescript: Beginner to Advanced
Typescript: Beginner to AdvancedTypescript: Beginner to Advanced
Typescript: Beginner to Advanced
 
Java Programming
Java ProgrammingJava Programming
Java Programming
 
Java: The Complete Reference, Eleventh Edition
Java: The Complete Reference, Eleventh EditionJava: The Complete Reference, Eleventh Edition
Java: The Complete Reference, Eleventh Edition
 
Introduction to Koltin for Android Part I
Introduction to Koltin for Android Part I Introduction to Koltin for Android Part I
Introduction to Koltin for Android Part I
 

Similar a Securing User Data with SQLCipher

Android Security: Defending Your Users
Android Security: Defending Your UsersAndroid Security: Defending Your Users
Android Security: Defending Your UsersCommonsWare
 
Backwards Compatibility: Strategies and Tactics
Backwards Compatibility: Strategies and TacticsBackwards Compatibility: Strategies and Tactics
Backwards Compatibility: Strategies and TacticsCommonsWare
 
App Integration (Revised and Updated)
App Integration (Revised and Updated)App Integration (Revised and Updated)
App Integration (Revised and Updated)CommonsWare
 
iOS application (in)security
iOS application (in)securityiOS application (in)security
iOS application (in)securityiphonepentest
 
What's New in Jelly Bean
What's New in Jelly BeanWhat's New in Jelly Bean
What's New in Jelly BeanCommonsWare
 
App integration: Strategies and Tactics
App integration: Strategies and TacticsApp integration: Strategies and Tactics
App integration: Strategies and TacticsCommonsWare
 
Evaluating iOS Applications
Evaluating iOS ApplicationsEvaluating iOS Applications
Evaluating iOS Applicationsiphonepentest
 
Android Security Humla Part 1
Android Security Humla Part 1Android Security Humla Part 1
Android Security Humla Part 1Nikhil Kulkarni
 
Mobile Application Security Code Reviews
Mobile Application Security Code ReviewsMobile Application Security Code Reviews
Mobile Application Security Code ReviewsDenim Group
 
Droidcon it-2014-marco-grassi-viaforensics
Droidcon it-2014-marco-grassi-viaforensicsDroidcon it-2014-marco-grassi-viaforensics
Droidcon it-2014-marco-grassi-viaforensicsviaForensics
 
Smart Phones Dumb Apps
Smart Phones Dumb AppsSmart Phones Dumb Apps
Smart Phones Dumb AppsDenim Group
 
ABS 2012 - Android Device Porting Walkthrough
ABS 2012 - Android Device Porting WalkthroughABS 2012 - Android Device Porting Walkthrough
ABS 2012 - Android Device Porting WalkthroughBenjamin Zores
 
JVM Multitenancy (JavaOne 2012)
JVM Multitenancy (JavaOne 2012)JVM Multitenancy (JavaOne 2012)
JVM Multitenancy (JavaOne 2012)Graeme_IBM
 
Is Android the New King of Embedded OSes at Embedded World 2014
Is Android the New King of Embedded OSes at Embedded World 2014Is Android the New King of Embedded OSes at Embedded World 2014
Is Android the New King of Embedded OSes at Embedded World 2014Opersys inc.
 

Similar a Securing User Data with SQLCipher (20)

Android Security: Defending Your Users
Android Security: Defending Your UsersAndroid Security: Defending Your Users
Android Security: Defending Your Users
 
Backwards Compatibility: Strategies and Tactics
Backwards Compatibility: Strategies and TacticsBackwards Compatibility: Strategies and Tactics
Backwards Compatibility: Strategies and Tactics
 
App Integration (Revised and Updated)
App Integration (Revised and Updated)App Integration (Revised and Updated)
App Integration (Revised and Updated)
 
iOS application (in)security
iOS application (in)securityiOS application (in)security
iOS application (in)security
 
What's New in Jelly Bean
What's New in Jelly BeanWhat's New in Jelly Bean
What's New in Jelly Bean
 
App integration: Strategies and Tactics
App integration: Strategies and TacticsApp integration: Strategies and Tactics
App integration: Strategies and Tactics
 
X Means Y
X Means YX Means Y
X Means Y
 
Android Attacks
Android AttacksAndroid Attacks
Android Attacks
 
Evaluating iOS Applications
Evaluating iOS ApplicationsEvaluating iOS Applications
Evaluating iOS Applications
 
Android Security Humla Part 1
Android Security Humla Part 1Android Security Humla Part 1
Android Security Humla Part 1
 
Help Doctor, my application is an onion!
Help Doctor, my application is an onion!Help Doctor, my application is an onion!
Help Doctor, my application is an onion!
 
Mobile Application Security Code Reviews
Mobile Application Security Code ReviewsMobile Application Security Code Reviews
Mobile Application Security Code Reviews
 
Droidcon it-2014-marco-grassi-viaforensics
Droidcon it-2014-marco-grassi-viaforensicsDroidcon it-2014-marco-grassi-viaforensics
Droidcon it-2014-marco-grassi-viaforensics
 
Smart Phones Dumb Apps
Smart Phones Dumb AppsSmart Phones Dumb Apps
Smart Phones Dumb Apps
 
ABS 2012 - Android Device Porting Walkthrough
ABS 2012 - Android Device Porting WalkthroughABS 2012 - Android Device Porting Walkthrough
ABS 2012 - Android Device Porting Walkthrough
 
SmartTV Security
SmartTV SecuritySmartTV Security
SmartTV Security
 
JVM Multitenancy (JavaOne 2012)
JVM Multitenancy (JavaOne 2012)JVM Multitenancy (JavaOne 2012)
JVM Multitenancy (JavaOne 2012)
 
Is Android the New King of Embedded OSes at Embedded World 2014
Is Android the New King of Embedded OSes at Embedded World 2014Is Android the New King of Embedded OSes at Embedded World 2014
Is Android the New King of Embedded OSes at Embedded World 2014
 
Introduction to android
Introduction to androidIntroduction to android
Introduction to android
 
Android Development Tutorial V3
Android Development Tutorial   V3Android Development Tutorial   V3
Android Development Tutorial V3
 

Más de CommonsWare

Gradle and Your Android Wearable Projects
Gradle and Your Android Wearable ProjectsGradle and Your Android Wearable Projects
Gradle and Your Android Wearable ProjectsCommonsWare
 
Getting Android Developers for Your Wearables
Getting Android Developers for Your WearablesGetting Android Developers for Your Wearables
Getting Android Developers for Your WearablesCommonsWare
 
When Microwatts Are Precious: Battery Tips for Wearable Apps
When Microwatts Are Precious: Battery Tips for Wearable AppsWhen Microwatts Are Precious: Battery Tips for Wearable Apps
When Microwatts Are Precious: Battery Tips for Wearable AppsCommonsWare
 
The Action Bar: Front to Back
The Action Bar: Front to BackThe Action Bar: Front to Back
The Action Bar: Front to BackCommonsWare
 
Secondary Screen Support Using DisplayManager
Secondary Screen Support Using DisplayManagerSecondary Screen Support Using DisplayManager
Secondary Screen Support Using DisplayManagerCommonsWare
 
Mastering the Master Detail Pattern
Mastering the Master Detail PatternMastering the Master Detail Pattern
Mastering the Master Detail PatternCommonsWare
 
Not Quite As Painful Threading
Not Quite As Painful ThreadingNot Quite As Painful Threading
Not Quite As Painful ThreadingCommonsWare
 
Android Development: The 20,000-Foot View
Android Development: The 20,000-Foot ViewAndroid Development: The 20,000-Foot View
Android Development: The 20,000-Foot ViewCommonsWare
 
Maps V2... And You!
Maps V2... And You!Maps V2... And You!
Maps V2... And You!CommonsWare
 
A Deep Dive Into ViewPager
A Deep Dive Into ViewPagerA Deep Dive Into ViewPager
A Deep Dive Into ViewPagerCommonsWare
 
Second-Screen Support in Android 4.2
Second-Screen Support in Android 4.2Second-Screen Support in Android 4.2
Second-Screen Support in Android 4.2CommonsWare
 
Integrate Android Apps and Web Apps
Integrate Android Apps and Web AppsIntegrate Android Apps and Web Apps
Integrate Android Apps and Web AppsCommonsWare
 
From Android to the Mobile Web
From Android to the Mobile WebFrom Android to the Mobile Web
From Android to the Mobile WebCommonsWare
 
The Wonderful World of Wearables
The Wonderful World of WearablesThe Wonderful World of Wearables
The Wonderful World of WearablesCommonsWare
 
Beaming Data to Devices with NFC
Beaming Data to Devices with NFCBeaming Data to Devices with NFC
Beaming Data to Devices with NFCCommonsWare
 
Making Money at Mobile: 60 Business Models
Making Money at Mobile: 60 Business ModelsMaking Money at Mobile: 60 Business Models
Making Money at Mobile: 60 Business ModelsCommonsWare
 
AppsWorld Keynote
AppsWorld KeynoteAppsWorld Keynote
AppsWorld KeynoteCommonsWare
 
Rich Text Editing and Beyond
Rich Text Editing and BeyondRich Text Editing and Beyond
Rich Text Editing and BeyondCommonsWare
 
Android Hardware That's A Little Bit... Odd
Android Hardware That's A Little Bit... OddAndroid Hardware That's A Little Bit... Odd
Android Hardware That's A Little Bit... OddCommonsWare
 
Google TV For Fun
Google TV For FunGoogle TV For Fun
Google TV For FunCommonsWare
 

Más de CommonsWare (20)

Gradle and Your Android Wearable Projects
Gradle and Your Android Wearable ProjectsGradle and Your Android Wearable Projects
Gradle and Your Android Wearable Projects
 
Getting Android Developers for Your Wearables
Getting Android Developers for Your WearablesGetting Android Developers for Your Wearables
Getting Android Developers for Your Wearables
 
When Microwatts Are Precious: Battery Tips for Wearable Apps
When Microwatts Are Precious: Battery Tips for Wearable AppsWhen Microwatts Are Precious: Battery Tips for Wearable Apps
When Microwatts Are Precious: Battery Tips for Wearable Apps
 
The Action Bar: Front to Back
The Action Bar: Front to BackThe Action Bar: Front to Back
The Action Bar: Front to Back
 
Secondary Screen Support Using DisplayManager
Secondary Screen Support Using DisplayManagerSecondary Screen Support Using DisplayManager
Secondary Screen Support Using DisplayManager
 
Mastering the Master Detail Pattern
Mastering the Master Detail PatternMastering the Master Detail Pattern
Mastering the Master Detail Pattern
 
Not Quite As Painful Threading
Not Quite As Painful ThreadingNot Quite As Painful Threading
Not Quite As Painful Threading
 
Android Development: The 20,000-Foot View
Android Development: The 20,000-Foot ViewAndroid Development: The 20,000-Foot View
Android Development: The 20,000-Foot View
 
Maps V2... And You!
Maps V2... And You!Maps V2... And You!
Maps V2... And You!
 
A Deep Dive Into ViewPager
A Deep Dive Into ViewPagerA Deep Dive Into ViewPager
A Deep Dive Into ViewPager
 
Second-Screen Support in Android 4.2
Second-Screen Support in Android 4.2Second-Screen Support in Android 4.2
Second-Screen Support in Android 4.2
 
Integrate Android Apps and Web Apps
Integrate Android Apps and Web AppsIntegrate Android Apps and Web Apps
Integrate Android Apps and Web Apps
 
From Android to the Mobile Web
From Android to the Mobile WebFrom Android to the Mobile Web
From Android to the Mobile Web
 
The Wonderful World of Wearables
The Wonderful World of WearablesThe Wonderful World of Wearables
The Wonderful World of Wearables
 
Beaming Data to Devices with NFC
Beaming Data to Devices with NFCBeaming Data to Devices with NFC
Beaming Data to Devices with NFC
 
Making Money at Mobile: 60 Business Models
Making Money at Mobile: 60 Business ModelsMaking Money at Mobile: 60 Business Models
Making Money at Mobile: 60 Business Models
 
AppsWorld Keynote
AppsWorld KeynoteAppsWorld Keynote
AppsWorld Keynote
 
Rich Text Editing and Beyond
Rich Text Editing and BeyondRich Text Editing and Beyond
Rich Text Editing and Beyond
 
Android Hardware That's A Little Bit... Odd
Android Hardware That's A Little Bit... OddAndroid Hardware That's A Little Bit... Odd
Android Hardware That's A Little Bit... Odd
 
Google TV For Fun
Google TV For FunGoogle TV For Fun
Google TV For Fun
 

Último

🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfhans926745
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 

Último (20)

🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 

Securing User Data with SQLCipher

  • 1. AnDevCon IV Securing User Data with SQLCipher Copyright © 2012 CommonsWare, LLC
  • 2. Workshop Overview ● Who Is At Risk? ● Offense and Defense ● SQLCipher Integration ● SQLCipher: Hands On! ● Encrypting SharedPreferences & Files ● Passphrases ● Encrypted Communications Copyright © 2012 CommonsWare, LLC
  • 3. Who Is At Risk? ● The Clumsy – Leaving phones lie around – Some percentage get personal data lifted ● The Traveler – Spear-fishing attack on a specific business – Corporate espionage or just garden-variety theft Copyright © 2012 CommonsWare, LLC
  • 4. Who Is At Risk? ● The Freedom Fighter – Devices used for communication, coordination – Devices confiscated upon arrest ● The Terrorist – Devices used for communication, coordination – Devices confiscated upon arrest Copyright © 2012 CommonsWare, LLC
  • 5. Who Is At Risk? ● The Citizen (of Repressive Regimes) – Arrests ranging from freedom of expression (protest rallies) to “just because” (race, religion, etc.) ● The User – May fall into any of the above categories – Even for apps not normally thought of as requiring such security Copyright © 2012 CommonsWare, LLC
  • 6. Who Is At Risk? ● The Developer – Press reports of “plaintext” stuff on internal storage – Negative publicity leads to negative reputation Copyright © 2012 CommonsWare, LLC
  • 7. Offense and Defense ● Defense: Lock Screen Security – Swipe: um, not really – Face: well, better than nothing – PIN: we're getting somewhere – Password: secure! ● Right? Copyright © 2012 CommonsWare, LLC
  • 8. Offense and Defense ● Offense: Exploits – Example: USB Debugging ● Create app that dismisses keyguard ● Run via USB cable and adb shell am ● Net: bypass lock screen regardless of security settings ● (according to Google: not a bug) Copyright © 2012 CommonsWare, LLC
  • 9. Offense and Defense ● Defense: Internal Storage – Read-write for app, deny-all for everyone else – User has no direct access via USB cable – Net: only way to get at the data is via the app! ● Right? Copyright © 2012 CommonsWare, LLC
  • 10. Offense and Defense ● Offense: Rooting – Most devices can be rooted – Can run apps as root, with access to all parts of internal storage – Run a file manager, copy off whatever is desired ● Or write an app that bulk-copies entire internal storage for later analysis Copyright © 2012 CommonsWare, LLC
  • 11. Offense and Defense ● Defense: Full-Disk Encryption – Entire internal storage bulk encrypted – Reboot locks down device, requiring manual entry of password – Many root attacks require a reboot – Net: only way to get at data is via encryption password! ● Right? Copyright © 2012 CommonsWare, LLC
  • 12. Offense and Defense ● Offense: Exploits – Ineffective against many temporary root attacks – Weak full-disk encryption passwords ● Same as lock screen for most devices ● Can be brute-forced – Assumes users know of, apply full-disk encryption ● Not offered during initial setup Copyright © 2012 CommonsWare, LLC
  • 13. Offense and Defense ● Defense: Cloud – Keep data off the device – Many Web sites and apps have decent defenses against brute-forcing attacks – So long as user is willing to enter password every time, the data is secure! ● Right? Copyright © 2012 CommonsWare, LLC
  • 14. Offense and Defense xkcd comics reproduced under CC license from Randall Munroe, despite Hat Guy's best efforts. Copyright © 2012 CommonsWare, LLC
  • 15. General Strategy ● Use Base Defenses – Lockscreen – Internal Storage – Full-Disk Encryption Copyright © 2012 CommonsWare, LLC
  • 16. General Strategy ● Per-App Crypto – More flexible authentication models ● Help to mitigate “always entering password” problem – Containers with better brute-force resistance – Storage Models ● Database ● SharedPreferences ● General files Copyright © 2012 CommonsWare, LLC
  • 17. Introducing SQLCipher ● SQLCipher – Modified version of SQLite – AES-256 encryption by default, of all data – Relatively low overhead – Cross-platform – BSD license Copyright © 2012 CommonsWare, LLC
  • 18. Introducing SQLCipher ● SQLCipher Security – Customizable encryption algorithm ● Based on OpenSSL libcrypto – Individual pages encrypted, with own initialization vector – Message authentication code (MAC) per page, to detect tampering – Hashed passphrase (PBKDF2) for key Xkcd comics reproduced under CC license from Randall Munroe. Hat guy is not impressed. Copyright © 2012 CommonsWare, LLC
  • 19. Introducing SQLCipher ● SQLCipher for Android – NDK-compiled binaries – Drop-in replacement classes for Android's SQLite classes ● SQLiteDatabase ● SQLiteOpenHelper ● Etc. Copyright © 2012 CommonsWare, LLC
  • 20. Introducing SQLCipher ● SQLCipher for Android Limitations – Adds ~3MB to APK size per CPU architecture – x86 binaries not available for public download right now ● Must build them yourself, versus downloading ARM binaries ● Available for this workshop! Copyright © 2012 CommonsWare, LLC
  • 21. Introducing SQLCipher ● SQLCipher and Third Party Code – Typically should work for open source via fork ● Replace their references to SQLite classes the same way you would replace your references ● Find way to pass in passphrase ● Either package as separate JAR or blend their source into your project as needed ● Examples: ORMLite, SQLiteAssetHelper Copyright © 2012 CommonsWare, LLC
  • 22. Integrating SQLCipher ● Step #1: Add to Project – Download ZIP file from: https://github.com/sqlcipher/android-database-sqlcipher – Copy ZIP's assets/ into project's assets/ – Copy ZIP's libs/ into project's libs/ Copyright © 2012 CommonsWare, LLC
  • 23. Integrating SQLCipher ● Step #2: Replace Import Statements – Eclipse ● Delete all android.database.* and android.database.sqlite.* imports ● Use Ctrl-Shift-O and choose the net.sqlcipher equivalents Copyright © 2012 CommonsWare, LLC
  • 24. Integrating SQLCipher ● Step #2: Replace Import Statements – Outside of Eclipse ● Replace all occurrences of android.database with net.sqlcipher, revert back as needed ● Replace all occurrences of android.database.sqlite with net.sqlcipher.database Copyright © 2012 CommonsWare, LLC
  • 25. Integrating SQLCipher ● Step #3: Supply Passphrases – SQLiteDatabase openOrCreateDatabase(), etc. – SQLiteOpenHelper getReadableDatabase() and getWritableDatabase() – Collect passphrase from user via your own UI Copyright © 2012 CommonsWare, LLC
  • 26. Integrating SQLCipher ● Step #4: Testing – Tests should work when starting with a clean install ● No existing unencrypted database ● Step #5: Beer! – Hooray, beer! Copyright © 2012 CommonsWare, LLC
  • 27. Integrating SQLCipher ● Upgrading to Encryption – Open unencrypted original – Create and ATTACH new encrypted database – sqlcipher_export() – Save schema version from old database – DETACH and close databases – Open encrypted database and set schema version Copyright © 2012 CommonsWare, LLC
  • 28. SQLCipher: Hands On! ● Option #1: Tutorial – Materials on USB thumb drive – Step-by-step instructions (PDF) – Live walkthrough of all steps ● Designed to supplement instructions – Goal: add SQLCipher to an existing Android app, including handling the database upgrade Copyright © 2012 CommonsWare, LLC
  • 29. SQLCipher: Hands On! ● Option #2: Upgrade Your Own App – Use instructions, walkthrough as guide for applying similar changes to your own code ● Warning: tutorial probably smaller than your app! ● Support – Ask questions of presenter, who will be up front or wandering around aimlessly between walkthrough sections Copyright © 2012 CommonsWare, LLC
  • 30. SQLCipher: Hands On! ● Option #3: Return at 11:25am for more exciting slides! – ...though we will all miss you... Copyright © 2012 CommonsWare, LLC
  • 31. SQLCipher: Hands On! ● Step #1: Getting Your Starting Point ● Step #2: Adding SQLCipher for Android ● Step #3: Adding a New Launcher Activity ● Step #4: Collect Passphrase For New Encryption ● Step #5: Create or Encrypt the Database ● Step #6: Collect Passphrase For Decryption Copyright © 2012 CommonsWare, LLC
  • 32. SQLCipher: Hands On! ● Step #1: Getting Your Starting Point ● Step #2: Adding SQLCipher for Android ● Step #3: Adding a New Launcher Activity ● Step #4: Collect Passphrase For New Encryption ● Step #5: Create or Encrypt the Database ● Step #6: Collect Passphrase For Decryption Copyright © 2012 CommonsWare, LLC
  • 33. SQLCipher: Hands On! ● Step #1: Getting Your Starting Point ● Step #2: Adding SQLCipher for Android ● Step #3: Adding a New Launcher Activity ● Step #4: Collect Passphrase For New Encryption ● Step #5: Create or Encrypt the Database ● Step #6: Collect Passphrase For Decryption Copyright © 2012 CommonsWare, LLC
  • 34. SQLCipher: Hands On! ● Step #1: Getting Your Starting Point ● Step #2: Adding SQLCipher for Android ● Step #3: Adding a New Launcher Activity ● Step #4: Collect Passphrase For New Encryption ● Step #5: Create or Encrypt the Database ● Step #6: Collect Passphrase For Decryption Copyright © 2012 CommonsWare, LLC
  • 35. SQLCipher: Hands On! ● Step #1: Getting Your Starting Point ● Step #2: Adding SQLCipher for Android ● Step #3: Adding a New Launcher Activity ● Step #4: Collect Passphrase For New Encryption ● Step #5: Create or Encrypt the Database ● Step #6: Collect Passphrase For Decryption Copyright © 2012 CommonsWare, LLC
  • 36. SQLCipher: Hands On! ● Step #1: Getting Your Starting Point ● Step #2: Adding SQLCipher for Android ● Step #3: Adding a New Launcher Activity ● Step #4: Collect Passphrase For New Encryption ● Step #5: Create or Encrypt the Database ● Step #6: Collect Passphrase For Decryption Copyright © 2012 CommonsWare, LLC
  • 37. SQLCipher: Hands On! ● Step #1: Getting Your Starting Point ● Step #2: Adding SQLCipher for Android ● Step #3: Adding a New Launcher Activity ● Step #4: Collect Passphrase For New Encryption ● Step #5: Create or Encrypt the Database ● Step #6: Collect Passphrase For Decryption Copyright © 2012 CommonsWare, LLC
  • 38. Encrypted SharedPreferences ● How They Are Normally Stored – Unencrypted XML files – Internal storage in shared_prefs/ directory ● Peer to your databases/, files/ directories ● Precise root path may vary, especially on Android 4.2 with multiple accounts Copyright © 2012 CommonsWare, LLC
  • 39. Encrypted SharedPreferences ● Introducing CWSharedPreferences – Strategy-based pluggable storage model ● SQLite ● SQLCipher ● Others as you wish via interfaces – Implements SharedPreferences ● Manual preference-using code requires no changes once you have your SharedPreferences object Copyright © 2012 CommonsWare, LLC
  • 40. Encrypted SharedPreferences ● Creating a SQLCipherStrategy – Supply name of preferences, passphrase, LoadPolicy ● LoadPolicy.SYNC: loads on main application thread ● LoadPolicy.ASYNC_BLOCK: loads in background thread, blocks if you try using them before loaded ● LoadPolicy.ASYNC_EXCEPTION: loads in background thread, raises exception if you try using them before loaded ● Test Case Walkthrough Copyright © 2012 CommonsWare, LLC
  • 41. Encrypted SharedPreferences ● Limitation: No PreferenceActivity – Hard-wired to use stock SharedPreferences ● Alternative: Encrypt at GUI Level – Custom Preference classes with encryption, decryption logic, also available for use outside of preference UI – Requires more manual fussing with encryption – Encrypts values, perhaps not keys Copyright © 2012 CommonsWare, LLC
  • 42. Encrypted Files ● Option #1: javax.crypto – Standard solution for Java for years – Plenty of online recipes – Search StackOverflow for Android-specific idiosyncrasies Copyright © 2012 CommonsWare, LLC
  • 43. Encrypted Files ● Option #2: SpongyCastle – Refactored version of BouncyCastle, to avoid VM collisions ● Android's javax.crypto based on BouncyCastle, but with somewhat hacked version – Fairly popular, probably less likely to run into Android-specific headaches Copyright © 2012 CommonsWare, LLC
  • 44. Encrypted Files ● Future Option: IOCipher – Uses SQLCipher as a backing store for virtual filesystem ● You work with drop-in replacement File class that stores, reads “files” as BLOBs from database – Benefits: less work, benefits of SQLCipher container – Pre-alpha Copyright © 2012 CommonsWare, LLC
  • 45. Passphrases ● Passphrase Entry Pain – Users do not like typing long passwords – Result = weaker quality – Option: “diceware” ● Choose ~5 words from stock list ● Can offer scrolling lists, auto-complete to help speed data entry ● Downside: more annoying for accessibility Copyright © 2012 CommonsWare, LLC
  • 46. Passphrases xkcd comics reproduced under CC license from Randall Munroe, even though Hat Guy owns a $5 wrench Copyright © 2012 CommonsWare, LLC
  • 47. Passphrases xkcd comics reproduced under CC license from Randall Munroe, but BYO talking horse Copyright © 2012 CommonsWare, LLC
  • 48. Passphrases ● Multi-Factor Authentication – Passphrase generated in code from user- supplied pieces – Organization options ● Simple concatenation ● Concatenation with factor prefix, un-typeable divider characters Copyright © 2012 CommonsWare, LLC
  • 49. Passphrases ● Multi-Factor Authentication Objectives – Longer passphrase without as much user input – Help defeat casual attacks ● Need all factors to access via your UI ● Otherwise, need to brute-force Copyright © 2012 CommonsWare, LLC
  • 50. Passphrases xkcd comics reproduced under CC license from Randall Munroe. Hat Guy is not amused. Copyright © 2012 CommonsWare, LLC
  • 51. Passphrases ● Multi-Factor Authentication Sources – NFC tag – QR code – Paired Bluetooth device – Wearable app – Gesture (e.g., pattern lock) – Biometrics (e.g., fingerprint scanner) Copyright © 2012 CommonsWare, LLC
  • 52. Passphrases ● Password Managers – Some offer APIs (e.g., OI Password Safe) – Benefit ● Easier: user does not have to remember as many passphrases – Downside ● Reliant upon third-party app and its security Copyright © 2012 CommonsWare, LLC
  • 53. Passphrases ● Changing SQLCipher Password – PRAGMA rekey = 'new passphrase'; – Requires access to database with existing key – Execution time proportional to database size ● Background thread, please! Copyright © 2012 CommonsWare, LLC
  • 54. Encrypted Communications ● BackupManager – No control over exactly where this data is sent ● Could be replaced by device manufacturers, carriers – Ideally, all data backed up should be encrypted with user passphrase ● Either because that data is always encrypted, or encrypt especially for backup/restore ● No sense in using static passphrase, as can be reverse-engineered Copyright © 2012 CommonsWare, LLC
  • 55. Encrypted Communications ● GCM and C2DM – Data is encrypted during transmission – Data is not encrypted at Google's servers – Options ● Encrypt the message payloads ● Message payloads are pointers to encrypted data held elsewhere Copyright © 2012 CommonsWare, LLC
  • 56. Encrypted Communications ● SSL: Basics – Use https:// URLs with URL or HttpClient – Use normally – Pray that your certificates are installed ● Self-signed certs ● Unusual certificate authorities ● Varying certificate authorities – http://goo.gl/8anF9 Copyright © 2012 CommonsWare, LLC
  • 57. Encrypted Communications ● SSL Attack: Hack the CA – Comodo, DigiNotar, etc. – Forged certificates claiming to be Google, Mozilla, Microsoft, etc. – “When an attacker obtains a fraudulent certificate, he can use it to eavesdrop on the traffic between a user and a website even while the user believes that the connection is secure.” Copyright © 2012 CommonsWare, LLC
  • 58. Encrypted Communications ● SSL Defense #1: Avoid CAs – CAs are needed for general-purpose clients (e.g., Web browsers) – If you control front end (app) and back end (Web service), use private SSL certificates that can be verified by the app itself – Moxie Marlinspike Implementation ● http://goo.gl/DYTrb ● See Option 1 Copyright © 2012 CommonsWare, LLC
  • 59. Encrypted Communications ● SSL Defense #2: Pinning – Assumes that you need to use a CA for some reason (e.g., Web site + Web service) – Validates issuing CA ● Rather than the certificate itself ● Limits attacks to ones where your CA gets hacked – Moxie Marlinspike Implementation ● http://goo.gl/DYTrb ● See Option 2 Copyright © 2012 CommonsWare, LLC
  • 60. Encrypted Communications ● SSL Defense #3: User Validation – Assume that attacks are infrequent – Alert user when you see a different certificate than used before ● May indicate a MITM attack – https://github.com/ge0rg/MemorizingTrustManager/wiki ● Implementation of trust store and UI Copyright © 2012 CommonsWare, LLC
  • 61. Encrypted Communications ● OnionKit – StrongTrustManager ● Customized set of CAs based on Debian cacerts file ● Full chain verification ● Limited pinning – Proxying through Orbot ● Tor implementation for Android – https://github.com/guardianproject/OnionKit Copyright © 2012 CommonsWare, LLC
  • 62. Summary ● Consider Encryption – ...even if you don't think you need it ● SQLCipher: Easiest Option for Encrypted Database – ...if you can live with the APK footprint ● Think About Encrypting Other Data Stores, Means of Collecting Passphrases ● Q&A Copyright © 2012 CommonsWare, LLC