[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["没有我需要的信息","missingTheInformationINeed","thumb-down"],["太复杂/步骤太多","tooComplicatedTooManySteps","thumb-down"],["内容需要更新","outOfDate","thumb-down"],["翻译问题","translationIssue","thumb-down"],["示例/代码问题","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-07-27。"],[],[],null,["# APK signature scheme v3.1\n\nOverview\n--------\n\nAndroid 13 supports APK signature scheme v3.1, an\nimprovement on the existing\n[APK signature scheme\nv3](/docs/security/features/apksigning/v3). The v3.1 scheme addresses some of the known issues with APK Signature\nScheme v3 regarding rotation. In particular, the v3.1\nsignature scheme supports SDK version targeting, which allows rotation to\ntarget a later release of the platform.\n\n\nThe v3.1 signature scheme uses a block ID that isn't recognized on Android\n12 or lower. Therefore, the platform applies the\nfollowing signer behavior:\n\n- Devices that run Android 13 or higher use the rotated signer in the v3.1 block.\n- Devices that run older versions of Android ignore the rotated signer and instead use the original signer in the v3 block.\n\nApps that haven't yet rotated their signing key don't require any additional\naction. Whenever these apps choose to rotate, the system applies the v3.1\nsignature scheme by default.\n\nv3.1 signing block\n------------------\n\nThe v3.1 signing block will have the same contents as the v3 signing block,\nbut with the new block ID these signatures\nwill only be recognized on devices running Android 13 and later.\nThis allows apps to safely rotate their signing keys without needing to worry about multi-target\nAPKs as the original signer can be used to sign the APK in the v3 signing\nblock and the rotated signer in the v3.1 signing block. This also allows the\nplatform to reuse all existing verification codes for the v3 signing block\nwhen verifying a v3.1 signature.\n\nBy default, the **apksig** library will use the\nv3.1 signing block whenever a rotated key and lineage is provided in the signing\nconfig. If an app's **minSdkVersion** is less than\nAndroid 13 and a rotated key is being used, the original signing key must be\nspecified as well so that it can be used to sign the APK in the v3 signing\nblock. This is similar to the current behavior where the original signer is\nrequired if the APK targets a version earlier than Android 9.\n\n\nTo support targeting key rotation starting from a particular SDK version,\nthe `apksig` library will expose new APIs that will allow\nsetting a minimum SDK version for rotation If an SDK version less\nthan Android 13 is specified as the minimum version for rotation support then\nthe original v3 block will be used. The v3.1 signing block is only used in the\npresence of rotation where the minimum SDK version for rotation is set to\nAndroid 13 and later. The v3 signing block will have a new attribute for rotation\nminimum SDK version stripping protection.\n\n| **APK Includes Lineage** | **Value of rotation-min-sdk-version** | **v3 signing block** | **v3.1 signing block** |\n|--------------------------|-------------------------------------------------|--------------------------------------------------------------|------------------------------------------------------------|\n| No | Default or any value (represented by *x* below) | Signed with original signer, targeting Android 9 and later | Not present |\n| Yes | Default | Signed with original signer, targeting Android 9 through 12L | Signed with rotated signer, targeting Android 13 and later |\n| Yes | *x* \\\u003c 33 (Android 13) | Signed with rotated signer, targeting Android 9 and later | Not present |\n| Yes | *x* \\\u003e= 33 (Android 13) | Signed with original signer, targeting Android 9 - (*x*-1) | Signed with rotated signer, targeting *x+* |\n\nRotation-related issues\n-----------------------\n\nThe following rotation-related problems have been resolved in the\nplatform:\n\n#### Android 12 fixes\n\n- The platform would only grant a signature permission to a requesting app if either app's current signer is in the signing lineage, or is the current signer, of the other app; this prevents granting a signature permission to a requesting app if the two apps follow signing key best practices and rotate to different signing keys.\n- The platform's APK rollback feature could not rollback an APK that just had its signing key rotated unless the previous key in the signing lineage had the rollback capability, but this capability defeats the purpose of rotation as it allows a new package update to be signed by the previous signing key and rolling back the rotated key.\n- An APK signed with only the rotated key and later updated with an APK signed with the original key and the rotated key in the lineage will only show the rotated key in the lineage on devices running Android 11 and earlier.\n\n#### Android 11 fixes\n\n- `PackageManager#checkSignatures` was not properly updated to check the original signing keys of two packages. This broke instrumentation for apps using a rotated signing key with the instrumentation APK using the original signing key.\n- Packages under a `sharedUserId` share their signing lineage. Whenever an app with an updated signing lineage is installed or updated in a `sharedUiserId` the lineage of that app replaced the shared lineage for the `sharedUserId` (that is, if an app's signing lineage were A -\\\u003e B, and an app is updated in the `sharedUserId` with lineage B -\\\u003e C, then the `sharedUserId` lineage would be replaced with B -\\\u003e C). Similarly capabilities of a previous signer in the lineage could not be updated unless the signing lineage were changed.\n| **Recommended:** It is recommended as part of best practices to rotate your app's signing key at least every **two** years.\n\nv4 integration\n--------------\n\nThe v4 signature scheme uses the signing config provided to apksigner; in the\ncase of multiple signing configs provided for rotation, the latest rotated\nsigning config is used. Prior to the introduction of v3.1, v3 only included this\nlatest rotated signing config, so v4 was able to use this config as is; with\nthis the v4 signature scheme was able to support rotation since it used the\nrotated signing key in its SigningInfo. While the v4 SigningInfo does not\ninclude the full signing lineage, it is able to pull this from the v3 signing\nblock to allow the platform access to the lineage for any signature queries.\nWhen v3.1 is in use to target rotation for the provided\nrotation-min-sdk-version, the generic v3 config will include both the original\nsigning config as well as the latest rotated signing config.\nAn extension of the v4 signature scheme has been created that includes additional\nsigning info blocks for each of the signing configs from the v3.1 block.\n\nValidation\n----------\n\n\nTo test your implementation of v3.1, run the\n`PkgInstallSignatureVerificationTest.java` CTS tests in\n`cts/hostsidetests/appsecurity/src/android/appsecurity/cts/`.\n\nFor more information about testing, check out the\n[verification](/docs/security/features/apksigning/v3#verification)\nsection in v3."]]