Introduction
An .idsig file holds the APK Signature Scheme v4 signature of an
Android package. It stands beside the APK under the same
name with .idsig added, as in app.apk.idsig. It signs the root
of a hash tree over every byte of the APK, so that Android 11 and later can check blocks
of the app while it is still being streamed to the device (incremental installation).
It does not replace the signature inside the APK: a v4 signature needs a v2 or v3 signature in the APK’s signing block.
Software
Structure
All numbers are little-endian, with no padding between fields. Every “bytes” item is an int32 length followed by that many bytes.
0version4 bytes4hashing information: how the tree is built, and its root hashvaries…signing information: certificate, public key and signatureup to 7,168 bytes and the length…Merkle tree of the APK (optional)varies
| Item | Type | Meaning |
|---|---|---|
| version | int32 | 2. |
| hashing_info | bytes | Contains: |
| hash_algorithm | int32 | 1 = SHA-256, the only value defined. |
| log2_blocksize | int8 | 12 (4,096-byte blocks), the only value defined. |
| salt | bytes | Salt of the tree, up to 32 bytes; apksig writes none. |
| raw_root_hash | bytes | Salted digest of the one page at the top of the tree. |
| signing_info | bytes | One signing information (below), then any number of further ones, each a block ID (int32) and a signing information as bytes. At most 7,168 bytes. |
| merkle_tree | bytes, optional | The whole tree. With it the signature is “complete”; without it, “stripped”. |
Signing information
| Item | Type | Meaning |
|---|---|---|
| apk_digest | bytes | A content digest taken from the APK’s v3 block, or from the v2 block if there is no v3: the first available of v3 chunked SHA-512, v3 verity SHA-256, v3 chunked SHA-256, v2 SHA-512 and v2 SHA-256. |
| x509_certificate | bytes | The signer’s certificate, DER. |
| additional_data | bytes | Free-form data; it is covered by the signature. |
| public_key | bytes | SubjectPublicKeyInfo, DER; it must match the certificate. |
| signature_algorithm_id | int32 | One of the APK signature algorithm IDs. |
| signature | bytes | Signature over the signed data (below). |
A further signing information with block ID 0x1B93AD61 goes with a v3.1
block in the APK: there is exactly one when the APK has such a block.
Signed data
The signature covers a block of bytes that is not stored in the file as it stands:
| Item | Type | Meaning |
|---|---|---|
| size | int32 | Size of the signed data, these 4 bytes included. |
| file_size | int64 | Size of the APK. |
| hash_algorithm, log2_blocksize | int32, int8 | As in the hashing information. |
| salt, raw_root_hash | bytes, bytes | As in the hashing information. |
| apk_digest, x509_certificate, additional_data | bytes each | As in the signing information. |
Merkle tree
The tree is that of Linux fs-verity. The APK is cut into 4,096-byte blocks, the last one filled with zeros, and each block is hashed with SHA-256. The hashes are packed into 4,096-byte pages, the last page filled with zeros, and the pages are hashed in the same way to make the level above, until a level fits in one page. The root hash is the hash of that page. A salt, when there is one, is filled with zeros to 64 bytes and put before every block or page that is hashed. In the file the levels are stored one after another, the top level first and the level of the APK’s own blocks last.
For a file that fits in one block the two differ: fs-verity takes the hash of that data
block as the root hash, while apksig still builds one page of hashes and
takes the hash of the page. The file explorer follows apksig.
In the file explorer
The file explorer shows an .idsig file field by field, with its signing
informations and the SHA-256 of each certificate. When the APK is beside it (the two
opened from a folder, or dropped together), Check against the APK rebuilds the
hash tree from the APK, compares it with the root hash and any stored tree, verifies the
v4 signature, matches it with the APK’s v2, v3 or v3.1 signer, and checks the APK’s own
signatures, all in the browser. No certificate chain or trust is checked. The stored
hash tree is shown level by level, in blocks of 128 hashes. A further signing
information is matched with the block its ID names; Android and apksig use
one only for v3.1, and any other is reported as such.
- An
.idsigfile over 256 MiB is not read. - The check of the APK’s own signatures has the limits listed for the signing block.
Not described
Known, not yet covered
- Viewer: an ML-DSA signature is reported as not checked in a browser whose Web Cryptography has no ML-DSA.
Links
Software
Developers
- apksig – the library behind apksigner (Java)
Reference
- APK Signature Scheme v4 – the Android Open Source Project’s description of the file
- fs-verity: Merkle tree – the Linux kernel’s description of the hash tree
Sources
Android Open Source Project: “APK Signature Scheme v4” (source.android.com); AOSP
tools/apksig: V4Signature, V4SchemeSigner,
VerityTreeBuilder and ApkVerifier. Linux kernel documentation:
“fs-verity: read-only file-based authenticity protection”.