03 Security Architecture I
03 Security Architecture I
Architecture I
Dr.-Ing. Sven Bugiel
2
Secure
Architecture
Principles
Basic Notions
General Security Objectives
4
Important security objectives in mobile context
• Privacy
− Confidentiality and integrity of personal data
− Easy? User wants to share some data, while protecting other data (=subjective
decisions)
− “Contextual integrity” by Helen Nissenbaum:
Parameters for CI = <data subject, sender of data, recipient of data, information type,
transmission principle>
• Integrity of system
− “Trusted computing base”: Software (and hardware) of a system responsible for enforcing
security policies
− TCB must be of integrity to enforce policies
• Integrity of applications’ code and data
− Applications and their data should not be compromised by other applications
• Confidentiality of applications’ data
• Authenticity of applications
• Others: Secure network connections,…
5
Example:
Package Integrity
and Authenticity
Package signing
7
Android package signature schemes
Backwards
compatible
8 https://source.android.com/security/images/apk-validation-process-v4.png
Recap: Application packages (APK)
9
Signature scheme v1 (JAR signing)
• Created with jarsigner or apksigner
• META-INF/
− Manifest.mf: List of files in the packages and their hash value
− <signer>.SF: List of resources and their signature value
− <signer>.{RSA,DSA,EC}: Certificate of the application (PKCS#7) and signature of the <signer>.SF file
− One pair per signing party
<signer>.{DSA,RSA,EC}
(PKCS #7 CMS ContentInfo with SignedData structure)
10 http://www.manpagez.com/man/1/jarsigner/
Example reading the certificate
11
Example reading the certificate
$ openssl pkcs7 -print_certs -inform DER -text -in BUBBLEWI.RSA
Certificate:
Data:
Version: 3 (0x2)
Serial Number: 1326376807 (0x4f0ee767)
Signature Algorithm: sha1WithRSAEncryption
Issuer: C=RO, ST=Romania, L=Bucharest, O=king.com, OU=Mobile, CN=Cristian Bidea
Validity
Not Before: Jan 12 14:00:07 2012 GMT
Not After : May 30 14:00:07 2039 GMT
Subject: C=RO, ST=Romania, L=Bucharest, O=king.com, OU=Mobile, CN=Cristian Bidea
Subject Public Key Info:
Public Key Algorithm: rsaEncryption
RSA Public Key: (2048 bit)
Modulus (2048 bit):
00:9d:48:8c:64:ae:53:7e:7c:6a:1a:f0:f3:cb:a0:
--snip--
a9:86:df:65:17:9c:09:d4:99:2e:24:09:ec:16:fe:
83:4d
Exponent: 65537 (0x10001)
Signature Algorithm: sha1WithRSAEncryption
7a:6d:d5:cc:78:6f:47:6b:62:9e:0e:9d:f0:2d:e6:68:9b:df:
--snip--
fc:7e:ff:c2:df:e8:e2:c6:6f:77:33:a0:da:4d:02:fb:72:0e:
8c:a2:50:1b
-----BEGIN CERTIFICATE-----
MIIDXDCCAkSgAwIBAgIETw7nZzANBgkqhkiG9w0BAQUFADBwMQswCQYDVQQGEwJSTzE
--snip--
v4VpENyOn0ImxcvBxCGDVd5l/awc5lY6nsAcY2nd4vseB6YEfhn8fv/C3+jixm93M6DaTQL7cg6MolAb
-----END CERTIFICATE-----
12
Example
$ cat MANIFEST.MF
Manifest-Version: 1.0
Created-By: 1.7.0_79 (Oracle Corporation)
Name: assets/res_output/levels/episode1233level3.txt
SHA1-Digest: uAgD/mKODBlLOIixDSd/deYOazs=
Name: assets/res_output/scenes/minishop/products/CandyMobileTencentSwedishFishPreGameEighteenCase2.xml
SHA1-Digest: J33CBVjTEOiDrvszXZ6DFn+Cng4=
Name: assets/res_output/shaders/uniformcolor.frag
SHA1-Digest: /hNps6PThR2g6FqSfuUqsu2x8pM=
Name: res/drawable/com_facebook_picker_list_longpressed.9.png
SHA1-Digest: /uU9+qqC9MjC0cwR3L+DskCy9xM=
Name: assets/res_output/scenes/conveyor_belt/down_to_right.xml
SHA1-Digest: aRcaTOzrRIbv1ASVmaUCXfhEouc=
Name: assets/res_output/tex/frog_grey.png
SHA1-Digest: YbBjHNd2Vy5Ls0tVMh0MhKFGqfQ=
--snip--
13
Example
$ cat BUBBLEWI.SF
Signature-Version: 1.0
SHA1-Digest-Manifest-Main-Attributes: x/m11ArtWWwg5I8p/wTD6UcKPdw=
Created-By: 1.7.0_79 (Oracle Corporation)
SHA1-Digest-Manifest: Mz7zDcEcRNkX0Vy34AE1/tSzQcA=
Name: assets/res_output/levels/episode1233level3.txt
SHA1-Digest: iBt3dPLBS4JbTjTx9pPk55vp0H0=
Name: assets/res_output/scenes/minishop/products/CandyMobileTencentSwedishFishPreGameEighteenCase2.xml
SHA1-Digest: x5qUIGs++x9nGl7ThbIpl/uiDnY=
Name: assets/res_output/shaders/uniformcolor.frag
SHA1-Digest: 5Eo8zgVaGcjIcseEfgGn8jn0C3U=
Name: res/drawable/com_facebook_picker_list_longpressed.9.png
SHA1-Digest: 2CGPL/jp5oPTQ2ltrIIWxbJ07UM=
Name: assets/res_output/scenes/conveyor_belt/down_to_right.xml
SHA1-Digest: FTVmxWzMVeExA0k5umb36rIOscs=
Name: assets/res_output/tex/frog_grey.png
SHA1-Digest: 5gL+KK2HiskUK0B2NeYEQhGAbn0=
Name: assets/res_output/sound/sounds/sugar_drops_spawn.ogg
SHA1-Digest: IhKwApDYfWf7hSeRrynQqV/ZJQc=
--snip--
14
Verifying of package manifest
Chain-of-Trust:
<signer>.{DSA,RSA,EC} ➔ <signer>.sf ➔ Manifest.mf ➔ Files
15
Benefits
• Integrity check
− Chain-of-trust ensures that the APK content has not been modified since
the developer created and signed the APK
16
APK Signing error a.k.a. “master key vulnerability”
(fixed now)
• Recap: Package signing
File Manifest.mf <signer>.sf
Manifest-Version: 1.0 Manifest-Version: 1.0
Created-By: 1.0 (Android) Created-By: 1.0 (Android)
SHA1-Digest-Manifest: f69XkdZ0/GvvTRhrLZ0tL7Q/zYw=
Hash Name: res/drawable-xhdpi/ic_launcher.png Hash
SHA1-Digest: AfPh3OJoypH966MludSW6f1RHg4= Name: res/drawable-xhdpi/ic_launcher.png
SHA1-Digest: cIga++hy5wqjHl9IHSfbg8tqCug=
ic_launcher.png Name: res/drawable-hdpi/ic_launcher.png
SHA1-Digest: Nq8q3HeTluE5JNCBpVvNy3BXtJI= Name: res/drawable-hdpi/ic_launcher.png
SHA1-Digest: stS7pUucSY0GgAVoESyO3Y7SanU=
…
ic_launcher.png
17
APK Signing error a.k.a. “master key vulnerability”
(fixed now)
• Vulnerability:
− Android verified the first file with identical name
− Android installed and used the second file
− Technical root cause: One library for verification, one for installation
• Allows attacker to append malicious files to APK, which are used and
installed instead of verified original!
ic_launcher.png
Install
18
APK Signature Scheme v2
19
Benefits (cont.)
• Integrity check
− Chain-of-trust ensures that the APK content has not been modified since
the developer created and signed the APK
• “Same origin policy”
− Updates of applications only allowed when update is signed with the
same developer key
20
Signature scheme v3 and v4
21
App bundles
• App Bundle (.aab) is the new, official publishing format (by Google)
− Bundles contains all code and resources, organized in modules
− Defers the APK generation and signing to Play
− Upload authenticated with a separate Upload Key
− Optional: developer can still be in charge of generation and signing
− Play decides which APK to generate for each user/platform
− Split APKs: Treat multiple APKs as one app (Base APK, Configuration
APKs, Feature module APKs)
https://developer.android.com/guide/app-bundle
22 https://developer.android.com/platform/technology/app-bundle
https://developer.android.com/studio/publish/app-signing
Benefits (cont.)
• Integrity check
− Chain-of-trust ensures that the APK content has not been modified since
the developer created and signed the APK
• “Same origin policy” (SOP)
− Updates of applications only allowed when update is signed with the
same developer key
− But: Google encourages self-signed certificates
− Authenticity of developer not ensured! No PKI to validate
developer certificate!
− “Trust on first install” when installing an app (not updating) the user
must be sure to have the “right” APK
23
Repackaging [9,10]
24
Prevalence of cloned apps [162]
25
Impact of Android Application Plagiarism [11]
26
Google’s SafetyNet Attestation API (deprecated)
• Anti-abuse API that allows app developers to assess the Android device their
app is running on
− Reports package name and hash → server can deny service to wrong app
Nonce, Platform config, App meta-data Nonce Nonce
SafetyNet Server SafetyNet API App App Server
S = Signed(Nonce, Platform config, App meta-data) S S
Can decide if
correct app on a
trusted platform
27 https://developer.android.com/training/safetynet/attestation
Google Play Integrity API
https://developer.android.com/privacy-and-security/safetynet
https://developer.android.com/google/play/integrity
28
Secure
Architecture
Principles
Isolation & Least Privilege
Fundamental security design principles
• Secure, fail-safe defaults: System should go into a secure state in the event
of a failure. For example, allow-listing instead of deny-listing. Errors in
configuration do not directly result in access to an asset.
• Complete mediation: Every access to an asset must be checked against the
security policy.
• Open design: Design should be open to scrutiny. Security of a system should
not depend on the secrecy of its protection mechanism. See also Kerckhoffs'
principle of cryptography.
30
Fundamental security design principles (cont.)
31
Fundamental security design principles (cont.)
• Isolation: Isolate critical resources physically or logically. Isolate data and process from
different users. Isolate protection mechanisms to avoid tampering with them.
− Encapsulation: Object-oriented form of isolation. For example: encapsulate data
objects in domain of its own such that internal structure only accessible through
procedures of the protected system and those procedures may only be called via
designated entry points.
• Modularity / Compartmentalization: Modular system architecture and security
mechanisms as isolated, protected modules. Helps protecting individual modules from
tampering.
• Defense-in-depth: Use multiple, overlapping protection approaches, the failure or
circumvention of any individual protection approach will not leave the system
unprotected. No single point of failure.
32
Fundamental security design principles (cont.)
33
Principles of Secure Design in Android
• Compartmentalization
• Isolation
• Principle of least privilege
34
Monolithic design
Network Network
35
Monolithic design
Network Network
36
Monolithic design
Network Network
37
Component design
Network Network
38
Component design
Network Network
39
Component design
Network Network
40
Principle of Least Privilege
• What is a ‘privilege’?
− Ability to access or modify a resource (e.g., file, hardware, networking)
− Privileged process: Process that has access to some resource not generally available
− More secure systems have many types of privilege
• Assume compartmentalization and isolation
− Separate the system into independent modules
− Limit interaction between modules
41
Abstract example
Network Network
42
Android Security
Architecture
Sandboxing
Sandboxing
General Idea
44
Application Isolation by Sandboxing
45
Process Tree on Linux
46
Process Tree on Android
47
Application Process Internals
App Process
Dalvik VM / ART
App Code
(Classes.dex)
JNI
Native code
Core libs (*.so)
syscalls
Kernel
JNI = Java Native Interface
48
Application Sandbox
App Process
Dalvik VM / ART
App Code
(Classes.dex)
JNI
Native code
Core libs (*.so)
syscalls
Kernel
49
Application Sandbox
Kernel
50
Multi-process Apps and Shared UIDs
(Deprecated since Android 10)
▪ Apps might consist of multiple processes (e.g., process attribute in manifest)
Kernel
51
Back to component design
Application
Framework
Linux Kernel
1) Fork() 3) setUID(A)
4) Give control flow to
VM process
53
Process Tree on Android
54
Predefined UIDs
https://cs.android.com/android
55
Attacks: Zimperlich root exploit (fixed now)
Zygote Dalvik VM
(root) RootA)
(UID
2) Load
App Code
APK
Core libs Core libs
1) Fork() 3) setUID(A)
4) Give control flow to
VM process
56
https://thesnkchrmr.wordpress.com/2011/03/24/rageagainstthecage/
Attacks: Breaking ASLR [110]
App Code
57
Private app directory
58
Private app directory
59
Predefined file access rights
$(Android_root_folder)/system/core/libcutils/fs_config.cpp
// Rules for directories.
// These rules are applied based on "first match", so they
// should start with the most specific path and work their
// way up to the root.
static const struct fs_path_config android_dirs[] = {
// clang-format off
{ 00770, AID_SYSTEM, AID_CACHE, 0, "cache" },
{ 00555, AID_ROOT, AID_ROOT, 0, "config" },
{ 00771, AID_SYSTEM, AID_SYSTEM, 0, "data/app" },
{ 00771, AID_SYSTEM, AID_SYSTEM, 0, "data/app-private" },
{ 00771, AID_SYSTEM, AID_SYSTEM, 0, "data/app-ephemeral" },
{ 00771, AID_ROOT, AID_ROOT, 0, "data/dalvik-cache" },
{ 00771, AID_SYSTEM, AID_SYSTEM, 0, "data/data" },
{ 00771, AID_SHELL, AID_SHELL, 0, "data/local/tmp" },
{ 00771, AID_SHELL, AID_SHELL, 0, "data/local" },
--snip--
https://cs.android.com/android
60
Selected Data Storage Options for apps
• Shared preferences
− Persistent key-value store across app restarts
− Supports MODE_PRIVATE: Data file will be saved readable only for the owning
app (default option)
SharedPreferences settings = getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
• Internal Storage
− Write files to the private app directory
− No need to know the absolute paths, use flags
FileOutputStream fos = openFileOutput(FILENAME, Context.MODE_PRIVATE);
• External storage
− Since Android v10/v11: Scoped storage: public abstract File getExternalFilesDir (String type)
− But: No privacy against apps with WRITE_EXTERNAL_STORAGE permission or a
granular read permission (e.g., READ_MEDIA_IMAGES)
https://developer.android.com/guide/topics/data
https://developer.android.com/reference/android/content/SharedPreferences
61 https://developer.android.com/about/versions/11/privacy/storage