Upgrade to Pro — share decks privately, control downloads, hide ads and more …

What's NNNNNNNNew in Android Security? - Oct 2016

What's NNNNNNNNew in Android Security? - Oct 2016

Android N brings a plethora of security enhancements to the platform and the SDK. Including Network Layer Security, Hardware-backed Keystore, APK Signing v2, Scoped Directory Access and Direct Boot.

Links in more clickable form on https://scottyab.com/2016/10/whats-new-in-android-security-oct-2016/

Scott Alexander-Bown

October 27, 2016
Tweet

More Decks by Scott Alexander-Bown

Other Decks in Technology

Transcript

  1. At a glance Direct boot Keystore ‘Securer’ networking Misc system

    and app differences Permissions in M @ScottyAB
  2. Terms 6.0 - M - API 23 - Marshmallow 7.0

    - N - API 24 - Nougat @ScottyAB
  3. Booting encrypted device pre-7.0 Boot halted for pin/password Device encrypted

    with same key Android used block-level encryption @ScottyAB
  4. Direct Boot mode Boot direct to lock screen Calls, SMS

    & Alarms work And your app too! @ScottyAB
  5. Direct Boot aware <receiver /> <receiver
 android:name=".directboot.MyDirectBootAwareReceiver"
 android:directBootAware="true">
 <intent-filter>
 <action

    android:name="android.intent.action.ACTION_LOCKED_BOOT_COMPLETED" />
 </intent-filter>
 </receiver> @ScottyAB
  6. Direct Boot aware <receiver /> <receiver
 android:name=".directboot.MyDirectBootAwareReceiver"
 android:directBootAware="true">
 <intent-filter>
 <action

    android:name="android.intent.action.ACTION_LOCKED_BOOT_COMPLETED" />
 </intent-filter>
 </receiver> @ScottyAB
  7. Accessing device encrypted storage @Override
 public void onReceive(Context context, Intent

    intent) {
 
 Context directBootContext = ContextCompat.createDeviceProtectedStorageContext(context);
 
 if (directBootContext != null) {
 SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(directBootContext);
 
 String token = sharedPreferences.getString(READ_ONLY_OAUTH_TOKEN, null);
 
 //do read only API lookup
 ///...
 }
 } @ScottyAB
  8. Accessing device encrypted storage @Override
 public void onReceive(Context context, Intent

    intent) {
 
 Context directBootContext = ContextCompat.createDeviceProtectedStorageContext(context);
 
 if (directBootContext != null) {
 SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(directBootContext);
 
 String token = sharedPreferences.getString(READ_ONLY_OAUTH_TOKEN, null);
 
 //do read only API lookup
 ///...
 }
 } @ScottyAB
  9. Accessing device encrypted storage @Override
 public void onReceive(Context context, Intent

    intent) {
 
 Context directBootContext = ContextCompat.createDeviceProtectedStorageContext(context);
 
 if (directBootContext != null) {
 SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(directBootContext);
 
 String token = sharedPreferences.getString(READ_ONLY_OAUTH_TOKEN, null);
 
 //do read only API lookup
 ///...
 }
 } @ScottyAB
  10. Direct Boot, so what is it good for? Messaging apps,

    important user notifications. Already using a BootCompleted listener? Recommended limited scope i.e Readonly API tokens @ScottyAB
  11. What is the KeyStore? Originally for unlocking DRM content App’s

    can securely create and store their crypto keys. Requires device pin or password (or fingerprint) Ideally secure element / Trust zone (hardware-based) @ScottyAB
  12. What’s new? Android M introduced broader range of capabilities. N+

    must be hardware backed (new devices) Time sensitive (Android M) @ScottyAB
  13. Attestation Key is baked into the firmware Create a Key

    Remotely validate its cert chain N+ (New hardware) @ScottyAB
  14. Securer Networking Custom trust store / anchors Debug only Overrides

    CA Block non https traffic Limit the certs you trust @ScottyAB
  15. Configuring CAs for Debugging Self signed certs in development Only

    enabled when android:debuggable=true Safer that conditional code @ScottyAB
  16. Pinning Certificates SSL pinning lets apps limit the set of

    certificates they accept Pin a hash of the SubjectPublicKeyInfo of the X.509 certificate. @ScottyAB
  17. SSL Pinning <network-security-config>
 <domain-config>
 <domain>scottyab.com</domain>
 <pin-set expiration="2017-10-28">
 <pin digest=“SHA-256”>7HIpactkIAq2Y49…Y=</pin>
 <!--

    backup pin -->
 <pin digest=“SHA-256”>fwza0LRMXouZHR…E=</pin>
 </pin-set>
 </domain-config>
 </network-security-config> 
 @ScottyAB
  18. How to get the Pin? $ openssl s_client -servername scottyab.com

    -connect scottyab.com:443 | openssl x509 - pubkey -noout | openssl rsa -pubin -outform der | openssl dgst -sha256 -binary | openssl enc -base64 Thanks to John Kozyrakis @ikoz @ScottyAB
  19. Under the hood The media stack and platform hardening Kernel

    hardening (with error correction) @ScottyAB
  20. App data directory App data directory now user only 700

    permissions Sharing files is explicitly opt-in Use FileProvider (support-lib) Training article “Sharing Files” @ScottyAB
  21. APK signing schema v2 Faster More Secure You’re already using

    both? zipalign before (not after) @ScottyAB
  22. Scoped directory access Access common external storage directories Storage Access

    Framework Environment.DIRECTORY_MOVIES Remember to call takePersistableUriPermission() @ScottyAB
  23. Misc differences No more access to MAC addresses Overlays can

    no longer be displayed on top of permissions dialogs Reduced the power of device admin applications @ScottyAB
  24. Runtime Permissions •Permissions that users “get” •Control on specific permissions

    •Easy for users •Updates don’t require approval @ScottyAB
  25. Tips of Working with Android Permissions Only use the permissions

    necessary for your app to work Be transparent Make system accesses explicit Context, Context, Context! @ScottyAB
  26. Thanks! Questions? Scott Alexander-Bown @ScottyAB [email protected] Shout outs: @commonsguy @ikoz

    +AdrianLudwig @doriancussen @niallscott @trionkidnapper @subsymbolics