MobDojoStart learning free

iOS Internals · Locks & Encryption · Lesson 2 of 5

Data Protection Classes

See why some files open after a restart and others stay locked until you unlock.

13 min60 XPLab in Pro

Four kinds of lock

An iPhone doesn't use one key for everything. Each file gets its own key, and that key is locked again by a class key. Apple's name for this system is Data Protection, and it turns on automatically when you set a passcode. Each file is placed in a protection class, which decides when the phone is able to open it.

There are four classes, named A to D:

App developers pick the class. A notes app with private journals might choose Complete Protection. A podcast app downloading episodes overnight needs something looser.

The simulated phone holds four files: Notes.db, the Mail inbox, the alarm clock settings and a file that's downloading. Tap Restart, then Unlock with passcode, then Lock screen, and watch which files are readable at each step.

Keys, passcodes and BFU

You saw in Mobile Fundamentals that a restarted phone is in BFU (Before First Unlock), and that your first unlock moves it to AFU (After First Unlock). Data Protection classes are what make that difference real.

Remember from the last module that your passcode is entangled with the Secure Enclave's UID. The keys for classes A, B and C are protected by that mix. So without your passcode, the phone itself can't unlock them. In BFU, only class D files and a few things the system needs to start up are readable. Your photos, messages and nearly all app data stay sealed.

When you first unlock, the phone unwraps the class keys and keeps them in memory. Then the classes behave differently:

Why isn't everything class A? Because many apps need to work while your phone sits in your pocket. Messages arrive, music plays, maps keep navigating. Class C is a practical middle ground. It protects data well against a thief who restarts the phone, but not against someone who gets hold of a phone that's already been unlocked since its last restart.

This is why a restart is such a strong security step. It drops every class key from memory, so the phone falls back to BFU. It's also why the passcode, not your face or fingerprint, is always needed after a restart. Only the passcode can rebuild those keys.

Class D has its own job. Its key is protected only by the UID and stored in a special area that can be wiped instantly, which makes erasing a phone fast.

Test yourself

Can you answer these?

  1. Right after a restart, before anyone has typed the passcode, which of the four files can the phone read?
  2. A thief grabs an iPhone that was unlocked this morning and has been locked for an hour. It hasn't restarted. Which file is still sealed by a key the phone doesn't have right now?

Answer them in the app to earn 60 XP (Pro).

Answer in the app