public class SigningCertificateLineage
extends java.lang.Object
The signer lineage contains a history of signing certificates with each ancestor attesting to the validity of its descendant. Each additional descendant represents a new identity that can be used to sign an APK, and each generation has accompanying attributes which represent how the APK would like to view the older signing certificates, specifically how they should be trusted in certain situations.
Its primary use is to enable APK Signing Certificate Rotation. The Android platform verifies the APK Signer Lineage, and if the current signing certificate for the APK is in the Signer Lineage, and the Lineage contains the certificate the platform associates with the APK, it will allow upgrades to the new certificate.
| Modifier and Type | Class and Description |
|---|---|
static class |
SigningCertificateLineage.Builder
Builder of
SigningCertificateLineage instances. |
static class |
SigningCertificateLineage.SignerCapabilities
Representation of the capabilities the APK would like to grant to its old signing
certificates.
|
static class |
SigningCertificateLineage.SignerConfig
Configuration of a signer.
|
| Modifier and Type | Field and Description |
|---|---|
static int |
MAGIC |
| Modifier and Type | Method and Description |
|---|---|
static SigningCertificateLineage |
consolidateLineages(java.util.List<SigningCertificateLineage> lineages)
Consolidates all of the lineages found in an APK into one lineage, which is the longest one.
|
byte[] |
generateV3SignerAttribute() |
java.util.List<java.security.cert.X509Certificate> |
getCertificatesInLineage()
Returns a list containing all of the certificates in the lineage.
|
SigningCertificateLineage.SignerCapabilities |
getSignerCapabilities(SigningCertificateLineage.SignerConfig config)
Returns the SignerCapabilities for the signer in the lineage that matches the provided
config.
|
SigningCertificateLineage.SignerCapabilities |
getSignerCapabilities(java.security.cert.X509Certificate cert)
Returns the SignerCapabilities for the signer in the lineage that matches the provided
certificate.
|
SigningCertificateLineage |
getSubLineage(java.security.cert.X509Certificate x509Certificate)
Returns a new SigingCertificateLineage which terminates at the node corresponding to the
given certificate.
|
boolean |
isCertificateInLineage(java.security.cert.X509Certificate cert)
Returns
true if the specified certificate is in the lineage. |
boolean |
isSignerInLineage(SigningCertificateLineage.SignerConfig config)
Returns
true if the specified config is in the lineage. |
static SigningCertificateLineage |
readFromApkDataSource(DataSource apk)
Extracts a Signing Certificate Lineage from the proof-of-rotation attribute in the V3
signature block of the provided APK DataSource.
|
static SigningCertificateLineage |
readFromApkFile(java.io.File apkFile)
Extracts a Signing Certificate Lineage from the proof-of-rotation attribute in the V3
signature block of the provided APK File.
|
static SigningCertificateLineage |
readFromDataSource(DataSource dataSource) |
static SigningCertificateLineage |
readFromFile(java.io.File file) |
static SigningCertificateLineage |
readFromSignedData(java.nio.ByteBuffer signedData)
Extracts a Signing Certificate Lineage from the proof-of-rotation attribute in the provided
signed data portion of a signer in a V3 signature block.
|
static SigningCertificateLineage |
readFromV3AttributeValue(byte[] attrValue)
Extracts a Signing Certificate Lineage from a v3 signer proof-of-rotation attribute.
|
int |
size()
The number of signing certificates in the lineage, including the current signer, which means
this value can also be used to V2determine the number of signing certificate rotations by
subtracting 1.
|
java.util.List<DefaultApkSignerEngine.SignerConfig> |
sortSignerConfigs(java.util.List<DefaultApkSignerEngine.SignerConfig> signerConfigs) |
SigningCertificateLineage |
spawnDescendant(SigningCertificateLineage.SignerConfig parent,
SigningCertificateLineage.SignerConfig child)
Add a new signing certificate to the lineage.
|
SigningCertificateLineage |
spawnDescendant(SigningCertificateLineage.SignerConfig parent,
SigningCertificateLineage.SignerConfig child,
SigningCertificateLineage.SignerCapabilities childCapabilities)
Add a new signing certificate to the lineage.
|
void |
updateSignerCapabilities(SigningCertificateLineage.SignerConfig config,
SigningCertificateLineage.SignerCapabilities capabilities)
Updates the SignerCapabilities for the signer in the lineage that matches the provided
config.
|
void |
writeToDataSink(DataSink dataSink) |
void |
writeToFile(java.io.File file) |
public static final int MAGIC
public static SigningCertificateLineage readFromFile(java.io.File file) throws java.io.IOException
java.io.IOExceptionpublic static SigningCertificateLineage readFromDataSource(DataSource dataSource) throws java.io.IOException
java.io.IOExceptionpublic static SigningCertificateLineage readFromV3AttributeValue(byte[] attrValue) throws java.io.IOException
readFromApkFile to handle this case.
attrValue - java.io.IOExceptionpublic static SigningCertificateLineage readFromApkFile(java.io.File apkFile) throws java.io.IOException, ApkFormatException
java.lang.IllegalArgumentException - if the provided APK does not contain a V3 signature block,
or if the V3 signature block does not contain a valid lineage.java.io.IOExceptionApkFormatExceptionpublic static SigningCertificateLineage readFromApkDataSource(DataSource apk) throws java.io.IOException, ApkFormatException
java.lang.IllegalArgumentException - if the provided APK does not contain a V3 signature block,
or if the V3 signature block does not contain a valid lineage.java.io.IOExceptionApkFormatExceptionpublic static SigningCertificateLineage readFromSignedData(java.nio.ByteBuffer signedData) throws java.io.IOException, ApkFormatException
java.lang.IllegalArgumentException - if the provided signed data does not contain a valid
lineage.java.io.IOExceptionApkFormatExceptionpublic void writeToFile(java.io.File file)
throws java.io.IOException
java.io.IOExceptionpublic void writeToDataSink(DataSink dataSink) throws java.io.IOException
java.io.IOExceptionpublic SigningCertificateLineage spawnDescendant(SigningCertificateLineage.SignerConfig parent, SigningCertificateLineage.SignerConfig child) throws java.security.cert.CertificateEncodingException, java.security.InvalidKeyException, java.security.NoSuchAlgorithmException, java.security.SignatureException
parent - current signing certificate of the containing APKchild - new signing certificate which will sign the APK contentsjava.security.cert.CertificateEncodingExceptionjava.security.InvalidKeyExceptionjava.security.NoSuchAlgorithmExceptionjava.security.SignatureExceptionpublic SigningCertificateLineage spawnDescendant(SigningCertificateLineage.SignerConfig parent, SigningCertificateLineage.SignerConfig child, SigningCertificateLineage.SignerCapabilities childCapabilities) throws java.security.cert.CertificateEncodingException, java.security.InvalidKeyException, java.security.NoSuchAlgorithmException, java.security.SignatureException
parent - current signing certificate of the containing APKchild - new signing certificate which will sign the APK contentschildCapabilities - flagsjava.security.cert.CertificateEncodingExceptionjava.security.InvalidKeyExceptionjava.security.NoSuchAlgorithmExceptionjava.security.SignatureExceptionpublic int size()
public byte[] generateV3SignerAttribute()
public java.util.List<DefaultApkSignerEngine.SignerConfig> sortSignerConfigs(java.util.List<DefaultApkSignerEngine.SignerConfig> signerConfigs)
public SigningCertificateLineage.SignerCapabilities getSignerCapabilities(SigningCertificateLineage.SignerConfig config)
public SigningCertificateLineage.SignerCapabilities getSignerCapabilities(java.security.cert.X509Certificate cert)
public void updateSignerCapabilities(SigningCertificateLineage.SignerConfig config, SigningCertificateLineage.SignerCapabilities capabilities)
public java.util.List<java.security.cert.X509Certificate> getCertificatesInLineage()
public boolean isSignerInLineage(SigningCertificateLineage.SignerConfig config)
true if the specified config is in the lineage.public boolean isCertificateInLineage(java.security.cert.X509Certificate cert)
true if the specified certificate is in the lineage.public SigningCertificateLineage getSubLineage(java.security.cert.X509Certificate x509Certificate)
x509Certificate - the signing certificate for which to searchjava.lang.IllegalArgumentException - if the provided certificate is not in the lineage.public static SigningCertificateLineage consolidateLineages(java.util.List<SigningCertificateLineage> lineages)