Search in sources :

Example 1 with SignerConfig

use of com.android.apksig.SigningCertificateLineage.SignerConfig in project apksig by venshine.

the class SigningCertificateLineageTest method testLineageFromAPKContainsExpectedSigners.

@Test
public void testLineageFromAPKContainsExpectedSigners() throws Exception {
    SignerConfig firstSigner = getSignerConfigFromResources(FIRST_RSA_2048_SIGNER_RESOURCE_NAME);
    SignerConfig secondSigner = getSignerConfigFromResources(SECOND_RSA_2048_SIGNER_RESOURCE_NAME);
    SignerConfig thirdSigner = getSignerConfigFromResources(THIRD_RSA_2048_SIGNER_RESOURCE_NAME);
    List<SignerConfig> expectedSigners = Arrays.asList(firstSigner, secondSigner, thirdSigner);
    DataSource apkDataSource = Resources.toDataSource(getClass(), "v1v2v3-with-rsa-2048-lineage-3-signers.apk");
    SigningCertificateLineage lineageFromApk = SigningCertificateLineage.readFromApkDataSource(apkDataSource);
    assertLineageContainsExpectedSigners(lineageFromApk, expectedSigners);
}
Also used : SignerConfig(com.android.apksig.SigningCertificateLineage.SignerConfig) DataSource(com.android.apksig.util.DataSource) Test(org.junit.Test)

Example 2 with SignerConfig

use of com.android.apksig.SigningCertificateLineage.SignerConfig in project apksig by venshine.

the class SigningCertificateLineageTest method createLineageWithSignersFromResources.

/**
 * Creates a new {@code SigningCertificateLineage} with the specified signers from the
 * resources. {@code mSigners} will be updated with the
 * {@code SigningCertificateLineage.SignerConfig} for each signer added to the lineage.
 */
private SigningCertificateLineage createLineageWithSignersFromResources(String oldSignerResourceName, String newSignerResourceName) throws Exception {
    SignerConfig oldSignerConfig = Resources.toLineageSignerConfig(getClass(), oldSignerResourceName);
    mSigners.add(oldSignerConfig);
    SignerConfig newSignerConfig = Resources.toLineageSignerConfig(getClass(), newSignerResourceName);
    mSigners.add(newSignerConfig);
    return new SigningCertificateLineage.Builder(oldSignerConfig, newSignerConfig).build();
}
Also used : SignerConfig(com.android.apksig.SigningCertificateLineage.SignerConfig)

Example 3 with SignerConfig

use of com.android.apksig.SigningCertificateLineage.SignerConfig in project apksig by venshine.

the class SigningCertificateLineageTest method updateLineageWithSignerFromResources.

/**
 * Updates the specified {@code SigningCertificateLineage} with the signer from the resources.
 * Requires that the {@code mSigners} list contains the previous signers in the lineage since
 * the most recent signer must be specified when adding a new signer to the lineage.
 */
private SigningCertificateLineage updateLineageWithSignerFromResources(SigningCertificateLineage lineage, String newSignerResourceName) throws Exception {
    // To add a new Signer to an existing lineage the config of the last signer must be
    // specified. If this class was used to create the lineage then the last signer should
    // be in the mSigners list.
    assertTrue("The mSigners list did not contain the expected signers to update the lineage", mSigners.size() >= 2);
    SignerConfig oldSignerConfig = mSigners.get(mSigners.size() - 1);
    SignerConfig newSignerConfig = Resources.toLineageSignerConfig(getClass(), newSignerResourceName);
    mSigners.add(newSignerConfig);
    return lineage.spawnDescendant(oldSignerConfig, newSignerConfig);
}
Also used : SignerConfig(com.android.apksig.SigningCertificateLineage.SignerConfig)

Example 4 with SignerConfig

use of com.android.apksig.SigningCertificateLineage.SignerConfig in project apksig by venshine.

the class SigningCertificateLineageTest method testUpdatedCapabilitiesInLineageWrittenToFile.

@Test
public void testUpdatedCapabilitiesInLineageWrittenToFile() throws Exception {
    SigningCertificateLineage lineage = createLineageWithSignersFromResources(FIRST_RSA_2048_SIGNER_RESOURCE_NAME, SECOND_RSA_2048_SIGNER_RESOURCE_NAME);
    SignerConfig oldSignerConfig = mSigners.get(0);
    List<Boolean> expectedCapabilityValues = Arrays.asList(false, false, false, false, false);
    SignerCapabilities newCapabilities = buildSignerCapabilities(expectedCapabilityValues);
    lineage.updateSignerCapabilities(oldSignerConfig, newCapabilities);
    File lineageFile = File.createTempFile(getClass().getSimpleName(), ".bin");
    lineageFile.deleteOnExit();
    lineage.writeToFile(lineageFile);
    lineage = SigningCertificateLineage.readFromFile(lineageFile);
    SignerCapabilities updatedCapabilities = lineage.getSignerCapabilities(oldSignerConfig);
    assertExpectedCapabilityValues(updatedCapabilities, expectedCapabilityValues);
}
Also used : SignerConfig(com.android.apksig.SigningCertificateLineage.SignerConfig) SignerCapabilities(com.android.apksig.SigningCertificateLineage.SignerCapabilities) File(java.io.File) Test(org.junit.Test)

Example 5 with SignerConfig

use of com.android.apksig.SigningCertificateLineage.SignerConfig in project apksig by venshine.

the class SigningCertificateLineageTest method testUpdatedCapabilitiesInLineage.

@Test
public void testUpdatedCapabilitiesInLineage() throws Exception {
    SigningCertificateLineage lineage = createLineageWithSignersFromResources(FIRST_RSA_2048_SIGNER_RESOURCE_NAME, SECOND_RSA_2048_SIGNER_RESOURCE_NAME);
    SignerConfig oldSignerConfig = mSigners.get(0);
    List<Boolean> expectedCapabilityValues = Arrays.asList(false, false, false, false, false);
    SignerCapabilities newCapabilities = buildSignerCapabilities(expectedCapabilityValues);
    lineage.updateSignerCapabilities(oldSignerConfig, newCapabilities);
    SignerCapabilities updatedCapabilities = lineage.getSignerCapabilities(oldSignerConfig);
    assertExpectedCapabilityValues(updatedCapabilities, expectedCapabilityValues);
}
Also used : SignerConfig(com.android.apksig.SigningCertificateLineage.SignerConfig) SignerCapabilities(com.android.apksig.SigningCertificateLineage.SignerCapabilities) Test(org.junit.Test)

Aggregations

SignerConfig (com.android.apksig.SigningCertificateLineage.SignerConfig)15 Test (org.junit.Test)12 SignerCapabilities (com.android.apksig.SigningCertificateLineage.SignerCapabilities)5 DataSource (com.android.apksig.util.DataSource)3 X509Certificate (java.security.cert.X509Certificate)2 ArrayList (java.util.ArrayList)2 File (java.io.File)1 PrivateKey (java.security.PrivateKey)1