Search in sources :

Example 11 with SigningConfiguration

use of com.android.tools.build.bundletool.model.SigningConfiguration in project bundletool by google.

the class BuildApksCommandTest method buildingViaFlagsAndBuilderHasSameResult_stamp_separateKeyAlias.

@Test
public void buildingViaFlagsAndBuilderHasSameResult_stamp_separateKeyAlias() throws Exception {
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    BuildApksCommand commandViaFlags = BuildApksCommand.fromFlags(new FlagParser().parse("--bundle=" + bundlePath, "--output=" + outputFilePath, "--aapt2=" + AAPT2_PATH, "--ks=" + keystorePath, "--ks-key-alias=" + KEY_ALIAS, "--ks-pass=pass:" + KEYSTORE_PASSWORD, "--key-pass=pass:" + KEY_PASSWORD, "--create-stamp=" + true, "--stamp-key-alias=" + STAMP_KEY_ALIAS, "--stamp-key-pass=pass:" + STAMP_KEY_PASSWORD), new PrintStream(output), systemEnvironmentProvider, fakeAdbServer);
    SigningConfiguration signingConfiguration = SigningConfiguration.builder().setSignerConfig(privateKey, certificate).build();
    SigningConfiguration stampSigningConfiguration = SigningConfiguration.builder().setSignerConfig(stampPrivateKey, stampCertificate).build();
    BuildApksCommand.Builder commandViaBuilder = BuildApksCommand.builder().setBundlePath(bundlePath).setOutputFile(outputFilePath).setSigningConfiguration(signingConfiguration).setSourceStamp(SourceStamp.builder().setSigningConfiguration(stampSigningConfiguration).build()).setAapt2Command(commandViaFlags.getAapt2Command().get()).setExecutorServiceInternal(commandViaFlags.getExecutorService()).setExecutorServiceCreatedByBundleTool(true).setOutputPrintStream(commandViaFlags.getOutputPrintStream().get());
    DebugKeystoreUtils.getDebugSigningConfiguration(systemEnvironmentProvider).ifPresent(commandViaBuilder::setSigningConfiguration);
    assertThat(commandViaBuilder.build().getSourceStamp()).isEqualTo(commandViaFlags.getSourceStamp());
    assertThat(commandViaBuilder.build().getSigningConfiguration()).isEqualTo(commandViaFlags.getSigningConfiguration());
}
Also used : PrintStream(java.io.PrintStream) ApksigSigningConfiguration(com.android.tools.build.bundletool.model.ApksigSigningConfiguration) SigningConfiguration(com.android.tools.build.bundletool.model.SigningConfiguration) ByteArrayOutputStream(java.io.ByteArrayOutputStream) FlagParser(com.android.tools.build.bundletool.flags.FlagParser) Test(org.junit.Test)

Example 12 with SigningConfiguration

use of com.android.tools.build.bundletool.model.SigningConfiguration in project bundletool by google.

the class BuildApksCommandTest method settingBothSigningConfigAndSigningConfigProvider_throwsError.

@Test
public void settingBothSigningConfigAndSigningConfigProvider_throwsError() {
    SigningConfiguration signingConfig = SigningConfiguration.builder().setSignerConfig(privateKey, certificate).build();
    ApksigSigningConfiguration apksigSigningConfig = ApksigSigningConfiguration.builder().setSignerConfigs(ImmutableList.of(SignerConfig.builder().setPrivateKey(privateKey).setCertificates(ImmutableList.of(certificate)).build())).build();
    IllegalStateException e = assertThrows(IllegalStateException.class, () -> BuildApksCommand.builder().setSigningConfiguration(signingConfig).setSigningConfigurationProvider(apkDescription -> apksigSigningConfig).build());
    assertThat(e).hasMessageThat().isEqualTo("Only one of SigningConfiguration or SigningConfigurationProvider should be set.");
}
Also used : ApksigSigningConfiguration(com.android.tools.build.bundletool.model.ApksigSigningConfiguration) ApksigSigningConfiguration(com.android.tools.build.bundletool.model.ApksigSigningConfiguration) SigningConfiguration(com.android.tools.build.bundletool.model.SigningConfiguration) Test(org.junit.Test)

Example 13 with SigningConfiguration

use of com.android.tools.build.bundletool.model.SigningConfiguration in project bundletool by google.

the class BuildApksCommandTest method buildingViaFlagsAndBuilderHasSameResult_stamp_sameSigningKey.

@Test
public void buildingViaFlagsAndBuilderHasSameResult_stamp_sameSigningKey() throws Exception {
    BuildApksCommand commandViaFlags = BuildApksCommand.fromFlags(new FlagParser().parse("--bundle=" + bundlePath, "--output=" + outputFilePath, "--aapt2=" + AAPT2_PATH, // Optional values.
    "--ks=" + keystorePath, "--ks-key-alias=" + KEY_ALIAS, "--ks-pass=pass:" + KEYSTORE_PASSWORD, "--key-pass=pass:" + KEY_PASSWORD, "--create-stamp=" + true), fakeAdbServer);
    SigningConfiguration signingConfiguration = SigningConfiguration.builder().setSignerConfig(privateKey, certificate).build();
    BuildApksCommand commandViaBuilder = BuildApksCommand.builder().setBundlePath(bundlePath).setOutputFile(outputFilePath).setSigningConfiguration(signingConfiguration).setSourceStamp(SourceStamp.builder().setSigningConfiguration(signingConfiguration).build()).setAapt2Command(commandViaFlags.getAapt2Command().get()).setExecutorServiceInternal(commandViaFlags.getExecutorService()).setExecutorServiceCreatedByBundleTool(true).setOutputPrintStream(commandViaFlags.getOutputPrintStream().get()).build();
    assertThat(commandViaBuilder.getSourceStamp()).isEqualTo(commandViaFlags.getSourceStamp());
    assertThat(commandViaBuilder.getSigningConfiguration()).isEqualTo(commandViaFlags.getSigningConfiguration());
}
Also used : ApksigSigningConfiguration(com.android.tools.build.bundletool.model.ApksigSigningConfiguration) SigningConfiguration(com.android.tools.build.bundletool.model.SigningConfiguration) FlagParser(com.android.tools.build.bundletool.flags.FlagParser) Test(org.junit.Test)

Example 14 with SigningConfiguration

use of com.android.tools.build.bundletool.model.SigningConfiguration in project bundletool by google.

the class BuildApksCommandTest method populateLineage_binaryFile.

@Test
public void populateLineage_binaryFile() throws Exception {
    SigningCertificateLineage.SignerConfig signerConfig = new SigningCertificateLineage.SignerConfig.Builder(privateKey, certificate).build();
    SigningCertificateLineage.SignerConfig oldestSignerConfig = new SigningCertificateLineage.SignerConfig.Builder(oldestSignerPrivateKey, oldestSignerCertificate).build();
    SigningCertificateLineage lineage = new SigningCertificateLineage.Builder(oldestSignerConfig, signerConfig).build();
    File lineageFile = tmpDir.resolve("lineage-file").toFile();
    lineage.writeToFile(lineageFile);
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    BuildApksCommand commandViaFlags = BuildApksCommand.fromFlags(new FlagParser().parse("--bundle=" + bundlePath, "--output=" + outputFilePath, "--aapt2=" + AAPT2_PATH, "--ks=" + keystorePath, "--ks-key-alias=" + KEY_ALIAS, "--ks-pass=pass:" + KEYSTORE_PASSWORD, "--key-pass=pass:" + KEY_PASSWORD, "--lineage=" + lineageFile, "--oldest-signer=" + oldestSignerPropertiesPath), new PrintStream(output), systemEnvironmentProvider, fakeAdbServer);
    SigningConfiguration signingConfiguration = commandViaFlags.getSigningConfiguration().get();
    assertThat(signingConfiguration.getSigningCertificateLineage().get().getCertificatesInLineage()).containsExactly(oldestSignerCertificate, certificate);
    assertThat(signingConfiguration.getOldestSigner().get().getPrivateKey()).isEqualTo(oldestSignerConfig.getPrivateKey());
    assertThat(signingConfiguration.getOldestSigner().get().getCertificates()).containsExactly(oldestSignerConfig.getCertificate());
}
Also used : PrintStream(java.io.PrintStream) SigningCertificateLineage(com.android.apksig.SigningCertificateLineage) ApksigSigningConfiguration(com.android.tools.build.bundletool.model.ApksigSigningConfiguration) SigningConfiguration(com.android.tools.build.bundletool.model.SigningConfiguration) SignerConfig(com.android.tools.build.bundletool.model.SignerConfig) ByteArrayOutputStream(java.io.ByteArrayOutputStream) FlagParser(com.android.tools.build.bundletool.flags.FlagParser) DeviceFactory.createDeviceSpecFile(com.android.tools.build.bundletool.testing.DeviceFactory.createDeviceSpecFile) File(java.io.File) CodeRelatedFile(com.android.bundle.CodeTransparencyOuterClass.CodeRelatedFile) Test(org.junit.Test)

Example 15 with SigningConfiguration

use of com.android.tools.build.bundletool.model.SigningConfiguration in project bundletool by google.

the class BuildApksCommandTest method populateRotationMinSdkVersion.

@Test
public void populateRotationMinSdkVersion() {
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    int rotationMinSdkVersion = 30;
    BuildApksCommand commandViaFlags = BuildApksCommand.fromFlags(new FlagParser().parse("--bundle=" + bundlePath, "--output=" + outputFilePath, "--aapt2=" + AAPT2_PATH, "--ks=" + keystorePath, "--ks-key-alias=" + KEY_ALIAS, "--ks-pass=pass:" + KEYSTORE_PASSWORD, "--key-pass=pass:" + KEY_PASSWORD, "--rotation-min-sdk-version=" + rotationMinSdkVersion), new PrintStream(output), systemEnvironmentProvider, fakeAdbServer);
    SigningConfiguration signingConfiguration = commandViaFlags.getSigningConfiguration().get();
    assertThat(signingConfiguration.getRotationMinSdkVersion()).hasValue(rotationMinSdkVersion);
}
Also used : PrintStream(java.io.PrintStream) ApksigSigningConfiguration(com.android.tools.build.bundletool.model.ApksigSigningConfiguration) SigningConfiguration(com.android.tools.build.bundletool.model.SigningConfiguration) ByteArrayOutputStream(java.io.ByteArrayOutputStream) FlagParser(com.android.tools.build.bundletool.flags.FlagParser) Test(org.junit.Test)

Aggregations

SigningConfiguration (com.android.tools.build.bundletool.model.SigningConfiguration)17 ApksigSigningConfiguration (com.android.tools.build.bundletool.model.ApksigSigningConfiguration)12 Test (org.junit.Test)12 FlagParser (com.android.tools.build.bundletool.flags.FlagParser)10 ByteArrayOutputStream (java.io.ByteArrayOutputStream)8 PrintStream (java.io.PrintStream)8 Path (java.nio.file.Path)5 SignerConfig (com.android.tools.build.bundletool.model.SignerConfig)4 CodeRelatedFile (com.android.bundle.CodeTransparencyOuterClass.CodeRelatedFile)3 Password (com.android.tools.build.bundletool.model.Password)3 File (java.io.File)3 SigningCertificateLineage (com.android.apksig.SigningCertificateLineage)2 ZipPath (com.android.tools.build.bundletool.model.ZipPath)2 DeviceFactory.createDeviceSpecFile (com.android.tools.build.bundletool.testing.DeviceFactory.createDeviceSpecFile)2 ApkVerifier (com.android.apksig.ApkVerifier)1 ApkFormatException (com.android.apksig.apk.ApkFormatException)1 ApkDescription (com.android.bundle.Commands.ApkDescription)1 ApkSet (com.android.bundle.Commands.ApkSet)1 BuildApksResult (com.android.bundle.Commands.BuildApksResult)1 Variant (com.android.bundle.Commands.Variant)1