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

Sign here, please!

Sign here, please!

An application ID might define your app among all others, but its signature is what proves and confirms its identity and integrity. From working in distributed teams to fending off fraudulent clones of your application, you eventually come to understand the importance of signatures.

In this talk we’ll take a deep dive into the Android keystore system, certificates and signatures, and go over key points necessary for any application’s long and productive life. Also, we will cover some security tips and tricks that will help ensure your app is safe to use, even if the users are faced with its evil twin.

At the end you should walk away with a deeper insight into everyday mechanisms that are often taken for granted, and the impact that they have on your users’ security.

Ana Baotić

March 26, 2018
Tweet

More Decks by Ana Baotić

Other Decks in Programming

Transcript

  1. SIGN HERE, PLEASE!
    ANA BAOTIĆ @abaotic

    View Slide

  2. View Slide

  3. View Slide

  4. Present in

    54

    countries
    Over
    22,300

    highly committed
    employees
    6th

    largest software
    & services
    vendor in Europe
    1,813

    m EUR
    sales revenues in
    2016
    176

    m EUR
    operating profit
    in 2016
    1bln

    EUR
    market
    capitalization
    • Founded in 1991
    • 6th largest software producer in Europe
    • Traded on the WSE, included in the WIG20 blue chip
    index
    • International presence
    ASSECO at a glance

    View Slide

  5. CERTIFICATE

    View Slide

  6. CERTIFICATE
    Electronic document that
    proves ownership of a public key
    X.509 - structure
    TLS/SSL, electronic signatures
    CERTIFICATE

    View Slide

  7. IDENTITY
    CERTIFICATE

    View Slide

  8. PUBLIC KEY
    CERTIFICATE = IDENTITY +
    +

    View Slide

  9. SIGNED BY CA
    CERTIFICATE = IDENTITY + PUBLIC KEY
    +
    +

    View Slide

  10. KEYS
    ASYMMETRIC CRYPTOGRAPHY

    View Slide

  11. KEYS
    ▸ Private (owner)
    ▸ Decrypts messages
    ▸ Calculates signatures
    ▸ Public (shared)
    ▸ Encrypts messages
    ▸ Confirms signatures

    View Slide

  12. DIGITAL SIGNATURE
    ▸ Calculate a digest/hash of the message
    ▸ Sender encrypts with private key
    ▸ Recipient decrypts with public key
    DIGITAL SIGNATURE

    View Slide

  13. CERTIFICATE = IDENTITY + PUBLIC KEY + SIGNED BY CA
    +
    +

    View Slide

  14. CERTIFICATE AUTHORITY
    CA
    Trusted entity that issues digital certificates.

    View Slide

  15. CA
    CA CERTIFICATE
    ▸ Self-signed certificate
    ▸ Browsers, Android, OSX
    ▸ Comodo, IdenTrust, Symantec, GoDaddy, Let’s Encrypt
    ▸ Impact of updates!

    View Slide

  16. CA - DOMAIN VS EXTENDED VALIDATION

    View Slide

  17. END CERTIFICATE

    View Slide

  18. INTERMEDIATE CERTIFICATE

    View Slide

  19. ROOT CERTIFICATE

    View Slide

  20. CERTIFICATES
    CERTIFICATE CHAINS

    View Slide

  21. CA
    SUBVERSION
    ▸ Primary risk key theft
    ▸ Scheme flawed
    ▸ HSM for key storage
    ▸ Offline

    View Slide

  22. TRUST
    ANDROID
    ▸ Unknown CA
    ▸ Self-signed
    ▸ No intermediate cert on server

    View Slide

  23. SIGNING ANDROID APPLICATIONS

    View Slide

  24. SIGNING ANDROID APPLICATIONS
    ▸ Generate a key and keystore
    ▸ Sign your application

    View Slide

  25. SIGNING ANDROID APPLICATIONS - NEW KEY STORE

    View Slide

  26. SIGNING ANDROID APPLICATIONS - SIGN THE APP

    View Slide

  27. SIGNING ANDROID APPLICATIONS - SIGN THE APP
    ALTERNATIVE
    ▸ keytool to generate a key
    ▸ zipalign to align unsigned apk
    ▸ jarsigner to sign aligned apk

    View Slide

  28. SIGN THE APK
    DECISIONS TO BE MADE
    ▸ Who will be responsible for the signing key?

    View Slide

  29. WE THE DEVELOPERS

    View Slide

  30. WE THE DEVELOPERS
    EXPECTATIONS
    ▸ Application can be updated throughout its lifetime

    View Slide

  31. WE THE DEVELOPERS
    PREREQUISITES
    ▸ Signing key must be safe
    ▸ Signing key must be accessible

    View Slide

  32. WE THE DEVELOPERS
    REALITY
    ▸ People spill coffee
    ▸ People switch companies

    View Slide

  33. WE THE DEVELOPERS
    REALITY NIGHTMARE
    signingConfigs {
    release {
    storeFile file("/not_where_you_think_it_is/ks.jks")
    storePassword "password"
    keyAlias "my-alias"
    keyPassword "password"
    }
    }

    View Slide

  34. GOOGLE PLAY APP SIGNING
    https://goo.gl/3aCBeC

    View Slide

  35. GOOGLE PLAY APP SIGNING
    DECISION IS PERMANENT

    View Slide

  36. GOOGLE PLAY APP SIGNING
    NEW APPS
    ▸ Create upload key and sign apk
    ▸ Google Play App Signing ->Accept
    ▸ Upload signed apk
    ▸ Register app signing key!

    View Slide

  37. GOOGLE PLAY APP SIGNING
    EXISTING APPS
    ▸ Opt-in
    ▸ Submit signing key to Google and
    ▸ Create upload key
    ▸ Update keystores
    ▸ Continue signing with upload key

    View Slide

  38. WE THE DEVELOPERS
    MITIGATION
    ▸ Upload key lost/compromised?

    View Slide

  39. SIGN THE APK
    DECISIONS TO BE MADE
    ▸ Who will be responsible for the signing key?
    ▸ Applicable to all modules/applications/flavours?

    View Slide

  40. SIGN THE APK
    PROS AND CONS
    ▸ Modularity
    ▸ Permission based
    sharing
    ▸ update-able
    ▸ Single point of failure

    View Slide

  41. View Slide

  42. ANDROID KEYSTORE SYSTEM

    View Slide

  43. ANDROID KEYSTORE SYSTEM
    The Android Keystore system safeguards your
    cryptographic keys from extraction.
    ANDROID KEYSTORE SYSTEM

    View Slide

  44. STORAGE
    SHOULD I KEEP SENSITIVE DATA IN MY APP?

    View Slide

  45. ANDROID KEYSTORE SYSTEM
    EXTRACTION PREVENTION
    ▸ System process in charge of cryptographic operations
    ▸ Key material bound to TEE, SE

    View Slide

  46. ANDROID KEYSTORE SYSTEM
    KEY USE AUTHORIZATIONS
    ▸ Once defined, immutable
    ▸ Cryptography
    ▸ Temporal validity interval
    ▸ User authentication

    View Slide

  47. ANDROID KEYSTORE SYSTEM
    UTILITY METHODS
    ▸ KeyInfo.isInsideSecurityHardware()
    ▸ KeyInfo.isUserAuthenticationRequirementEnforcedBySecureHardware()

    View Slide

  48. ANDROID KEYSTORE SYSTEM
    KEYCHAIN VS ANDROID KEYSTORE PROVIDER
    ▸ System-wide credentials
    ▸ System provided UI
    ▸ App-specific credentials
    ▸ No interaction
    ▸ AndroidKeystore API 18

    View Slide

  49. KEY PAIR ENTRY IN KEYSTORE
    KeyPairGenerator kpg = KeyPairGenerator.getInstance(
    KeyProperties.KEY_ALGORITHM_EC, "AndroidKeyStore");
    kpg.initialize(new KeyGenParameterSpec.Builder(
    alias,
    KeyProperties.PURPOSE_SIGN | KeyProperties.PURPOSE_VERIFY)
    .setDigests(KeyProperties.DIGEST_SHA256,
    KeyProperties.DIGEST_SHA512)
    .build());
    KeyPair kp = kpg.generateKeyPair();

    View Slide

  50. KEY PAIR ENTRY IN KEYSTORE
    KeyPairGenerator kpg = KeyPairGenerator.getInstance(
    KeyProperties.KEY_ALGORITHM_EC, "AndroidKeyStore");
    kpg.initialize(new KeyGenParameterSpec.Builder(
    alias,
    KeyProperties.PURPOSE_SIGN | KeyProperties.PURPOSE_VERIFY)
    .setDigests(KeyProperties.DIGEST_SHA256,
    KeyProperties.DIGEST_SHA512)
    .build());
    KeyPair kp = kpg.generateKeyPair();

    View Slide

  51. KEY PAIR ENTRY IN KEYSTORE
    KeyPairGenerator kpg = KeyPairGenerator.getInstance(
    KeyProperties.KEY_ALGORITHM_EC, "AndroidKeystore");
    kpg.initialize(new KeyGenParameterSpec.Builder(
    alias,
    KeyProperties.PURPOSE_SIGN | KeyProperties.PURPOSE_VERIFY)
    .setDigests(KeyProperties.DIGEST_SHA256,
    KeyProperties.DIGEST_SHA512)
    .build());
    KeyPair kp = kpg.generateKeyPair();

    View Slide

  52. LISTING ENTRIES
    KeyStore ks = KeyStore.getInstance("AndroidKeyStore");
    ks.load(null);
    Enumeration aliases = ks.aliases();

    View Slide

  53. LISTING ENTRIES
    KeyStore ks = KeyStore.getInstance("AndroidKeyStore");
    ks.load(null);
    Enumeration aliases = ks.aliases();

    View Slide

  54. SIGNING DATA
    Signature s = Signature.getInstance("SHA256withECDSA");
    s.initSign(((PrivateKeyEntry) entry).getPrivateKey());
    s.update(data);
    byte[] signature = s.sign();

    View Slide

  55. SIGNING DATA
    Signature s = Signature.getInstance("SHA256withECDSA");
    s.initSign(((PrivateKeyEntry) entry).getPrivateKey());
    s.update(data);
    byte[] signature = s.sign();

    View Slide

  56. VERIFYING SIGNATURES
    Signature s = Signature.getInstance("SHA256withECDSA");
    s.initVerify(((PrivateKeyEntry) entry).getCertificate());
    s.update(data);
    boolean valid = s.verify(signature);

    View Slide

  57. VERIFYING SIGNATURES
    Signature s = Signature.getInstance("SHA256withECDSA");
    s.initVerify(((PrivateKeyEntry) entry).getCertificate());
    s.update(data);
    boolean valid = s.verify(signature);

    View Slide

  58. KEY ATTESTATION
    KEY ATTESTATION
    ▸ Is a key stored in hardware-backed keystore
    ▸ Small number of devices API 24+

    View Slide

  59. TEXT

    View Slide

  60. FRAGMENTATION
    ANDROID P(ANCAKE?)
    ▸ Key rotation
    ▸ StrongBox Keymaster (HSM)
    ▸ …

    View Slide

  61. GOOGLE TRANSPARENCY REPORT
    https://transparencyreport.google.com/

    View Slide

  62. QUALYS
    CHECK YOUR DOMAIN (NOW!)
    https://www.ssllabs.com/ssltest/analyze.html

    View Slide

  63. THANK YOU!
    Q&A

    View Slide