Skip to main content
coreydaley.dev

An Apple Encrypted Archive that isn't encrypted

I ran aea encrypt on a text file with one sentence repeated 200 times, with compression turned off. Then I searched the encrypted output for that sentence and found all 200 copies, sitting in the file as plain text.

Turning compression back on hid them from grep, but not from anyone who knows what LZFSE is.

None of that is a bug. It’s profile 0 of Apple Encrypted Archive (AEA), the profile Xcode now ships in, and it’s doing what Apple’s own manual page says it does. The problem is the name. A file called an encrypted archive, made by a command called encrypt, is easy to write down wrong in a threat model.

In my post on Xcode’s move from .xip to .aea I said profile 0 is “signed, not encrypted” and that anyone can read it. I hadn’t tested the second half. Then a reader on LinkedIn pointed out the threat-model problem and asked a sharper question: does archiveutil check the signature before it starts writing files, or only once it’s done? So I tested both: what profile 0 doesn’t protect, and what it does.

Everything here was run on macOS 27.2.1 on an M2 Pro MacBook Pro, with throwaway keys and a test file, plus the Xcode 27.3 beta 2 .aea.

The name and the profiles

AEA has six profiles, and the name of each spells out what it does:

0: hkdf_sha256_hmac__none__ecdsa_p256
1: hkdf_sha256_aesctr_hmac__symmetric__none
2: hkdf_sha256_aesctr_hmac__symmetric__ecdsa_p256
3: hkdf_sha256_aesctr_hmac__ecdhe_p256__none
4: hkdf_sha256_aesctr_hmac__ecdhe_p256__ecdsa_p256
5: hkdf_sha256_aesctr_hmac__scrypt__none

aesctr is the encryption. Profiles 1 to 5 have it; profile 0 doesn’t. Where the others name a symmetric key, a recipient’s key or a password, profile 0 says none. Apple doesn’t hide this: man aea describes profile 0 as “no encryption, signed”. What it has is an HMAC over the data and an ECDSA signature, so you can tell whether the file was changed and who signed it. Nothing about it is secret.

What anyone can read

aea encrypt -profile 0 is a valid command. It ran without a warning, exited 0, and gave me a .aea. I made a 10,800-byte text file, one sentence repeated 200 times, and a throwaway P-256 signing key, then made profile-0 archives from it. Here’s what it took to get the text back:

ArchiveWhat it took to read the text
Profile 0, no compression (-a none)Nothing. grep -a finds all 200 lines in the .aea.
Profile 0, default compression (LZFSE)Nothing secret. grep finds none, but macOS’s compression_tool -decode -a lzfse, run on the bytes from where the LZFSE stream starts (bvx2), gave back the original file byte for byte.
Profile 0, read with aea decryptThe signer’s public key. Output matched the original byte for byte.
Profile 5 (password), controlgrep finds none, and a wrong password fails (“Failed to unlock container”).

The middle row matters most. With compression on, which is the default, the file looks encrypted: your secret isn’t anywhere in it as text. It’s only compressed. I only tried the compression_tool route on this small file, but aea decrypt with nothing but a public key worked on every profile-0 file I tried.

That includes Xcode’s. The .aea carries a three-certificate chain: a signing certificate issued by Apple Platform Signing ECC CA 1 - G1, which chains to Apple Root CA - G3. I took the public key from the signing certificate and passed it to aea decrypt, asking for the first 4 KB. Out came an ordinary Apple Archive, starting with AA01 and the paths Xcode-beta.app and Xcode-beta.app/Contents. That isn’t a leak, since Xcode is free to download. It’s what profile 0 means: everything needed to read the file comes with the file.

One thing that doesn’t prove: a key taken from the file only tells you the file matches itself. Whether that certificate really chains to Apple is a separate check, which is the one tools like archiveutil and xcodeinstall make.

What profile 0 does protect

The signature and the HMAC are real, and they held up in every test I ran.

With my test archive:

  • The wrong public key was refused: “Signature verification” failed and no data came out.
  • One flipped byte, 200 bytes from the end, with the right key, was refused too: “HMAC verification” failed and no data came out.

Both left an empty output file behind, so a script should check the exit code rather than whether a file exists.

Then the reader’s question. I flipped one byte in three copies of the Xcode .aea and ran archiveutil extractXcodeAEA on each in an empty folder, checking every second what had appeared in the folder:

Byte flippedResultFailed afterWritten to the folder
Inside the signatureexit 10.06 snothing
Middle of the fileexit 15.7 snothing
1 MiB from the endexit 19.2 snothing
None (control)success64.7 sXcode-beta.app

The control run shows the order. For the first ten seconds nothing appeared and free disk space didn’t move, which looks like archiveutil checking the whole file. The tampered copies all failed inside that window, later the further into the file the bad byte was. Only after that did it start writing.

In the successful run, the folder never held a half-written Xcode either. While about 4 GB was being written, all it held was an empty file named Xcode-beta.app. The real app was written somewhere else on the disk and moved into place when extraction finished. I didn’t test what’s left behind if you interrupt it.

The one thing it does badly is the error message. A tampered archive gets “The operation couldn’t be completed. Invalid argument”, with nothing about a signature. In the earlier post, a file I’d signed with my own key got the same message. So in a CI log, “Invalid argument” can mean “not signed by Apple” or “changed since Apple signed it”, and it won’t say which.

What I got wrong

  • I published “anyone can read it” before testing it. It turned out to be true, but in the earlier post it was a reading of the profile name, not a result.
  • “I can’t find it with grep” is not a test for encryption. With compression on, a plain grep finds nothing, and the file is still fully readable. Worse, the grep in the shell Claude Code runs my commands in skips binary files: on the uncompressed archive it printed nothing, while macOS’s /usr/bin/grep counted all 200 lines. I happened to switch to /usr/bin/grep -a before trusting it.
  • Purrchiver believed the name too. It saw an encrypted archive and asked for a password, which is the same mistake in code. The earlier post covers what’s changing.

If you use AEA

  • To keep contents private, pick a profile with aesctr in its name: 5 for a password, 1 or 2 for a symmetric key, 3 or 4 to encrypt for a recipient’s public key. Profiles 2 and 4 also sign.
  • Check what you were given. aea id -v -i file.aea prints the profile (without -v you only get an ID). No aesctr, no encryption.
  • In a threat model, write profile 0 as “signed”. It shows who signed the file and that it wasn’t changed. It doesn’t keep anything secret.
  • For Xcode, let archiveutil do the checking. In my tests it refused every tampered copy before writing anything to the folder. Check its exit code, since its error message won’t tell you why it failed.

Is there a file in your pipeline, or a line in your threat model, that’s labelled “encrypted” only because of what it’s called?

Related posts